执行下面的代码会发生什么?
package main
import (
"fmt"
"time"
)
func main() {
ch := make(chan int, 1000)
go func() {
for i := 0; i < 10; i++ {
ch <- i
}
}()
go func() {
for {
a, ok := <-ch
if !ok {
fmt.Println("close")
return
}
fmt.Println("a: ", a)
}
}()
close(ch)
fmt.Println("ok")
time.Sleep(time.Second * 100)
}
ok
close
panic: send on closed channel
goroutine 6 [running]:
对已经关闭的管道写数据会发生panic 对已经关闭的管道读数据,无已写缓存的情况下读的是零值