daily pastebin goal
11%
SHARE
TWEET

[Go] Closing channels.

cwchen Nov 28th, 2017 419 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6.     ch := make(chan int, 4)
  7.     ch <- 2
  8.     ch <- 4
  9.     close(ch)
  10.     // ch <- 6 // panic, send on closed channel
  11.  
  12.     fmt.Println(<-ch)
  13.     fmt.Println(<-ch)
  14.     fmt.Println(<-ch) // closed, returns zero value for element
  15. }
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