Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "bufio"
- "fmt"
- "os"
- )
- func main() {
- var channel = make(chan int, 0)
- go subscriber(channel)
- go publisher(channel)
- fmt.Println("Key to end")
- bufio.NewReader(os.Stdin).ReadBytes('\n')
- }
- func subscriber(channel chan int) {
- for {
- value := <-channel
- fmt.Println("Received ", value)
- }
- }
- func publisher(channel chan int) {
- for i := 0; i < 10; i++ {
- fmt.Println("pushing ", i)
- channel <- i
- }
- }
Add Comment
Please, Sign In to add comment