channel_block3.go 282 B

1234567891011121314151617181920212223
  1. package main
  2. import "fmt"
  3. import "time"
  4. func main() {
  5. c := make(chan int)
  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. (15 s later):
  18. received 10
  19. sent 10
  20. */