Guest User

Untitled

a guest
Feb 17th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "bufio"
  5. "fmt"
  6. "os"
  7. )
  8.  
  9. func main() {
  10. var channel = make(chan int, 0)
  11.  
  12. go subscriber(channel)
  13. go publisher(channel)
  14.  
  15. fmt.Println("Key to end")
  16. bufio.NewReader(os.Stdin).ReadBytes('\n')
  17. }
  18.  
  19. func subscriber(channel chan int) {
  20. for {
  21. value := <-channel
  22. fmt.Println("Received ", value)
  23. }
  24. }
  25.  
  26. func publisher(channel chan int) {
  27. for i := 0; i < 10; i++ {
  28. fmt.Println("pushing ", i)
  29. channel <- i
  30. }
  31. }
Add Comment
Please, Sign In to add comment