daily pastebin goal
69%
SHARE
TWEET

[Go] Using directed channels.

cwchen Nov 28th, 2017 597 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top