Advertisement
cwchen

[Go] Using directed channels.

Nov 28th, 2017
1,065
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.36 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func ping(pings chan<- string, msg string) {
  6.     pings <- msg
  7. }
  8.  
  9. func pong(pings <-chan string, pongs chan<- string) {
  10.     msg := <-pings
  11.     pongs <- msg
  12. }
  13.  
  14. func main() {
  15.     pings := make(chan string, 1)
  16.     pongs := make(chan string, 1)
  17.     ping(pings, "passed message")
  18.     pong(pings, pongs)
  19.     fmt.Println(<-pongs)
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement