goroutine_panic.go 250 B

12345678910111213141516171819202122
  1. package main
  2. import (
  3. "fmt"
  4. )
  5. func tel(ch chan int) {
  6. for i := 0; i < 15; i++ {
  7. ch <- i
  8. }
  9. }
  10. func main() {
  11. var ok = true
  12. ch := make(chan int)
  13. go tel(ch)
  14. for ok {
  15. i := <-ch
  16. fmt.Printf("ok is %t and the counter is at %d\n", ok, i)
  17. }
  18. }