channel_buffer.go 329 B

12345678910111213141516171819202122
  1. package main
  2. import "fmt"
  3. import "time"
  4. func main() {
  5. c := make(chan int, 50)
  6. go func() {
  7. time.Sleep(15 * 1e9)
  8. x := <-c
  9. fmt.Println("received", x)
  10. }()
  11. fmt.Println("sending", 10)
  12. c <- 10
  13. fmt.Println("sent", 10)
  14. }
  15. /* Output:
  16. sending 10
  17. sent 10 // prints immediately
  18. no further output, because main() then stops
  19. */