golang中在一个值为 nil 的 channel 上发送和接收数据将永久阻塞
package main
import (
"fmt"
"time"
)
func main() {
ch := make(chan int)
for i := 0; i < 3; i++ {
go func(idx int) {
ch <- idx
}(i)
}
fmt.Println(<-ch)
close(ch)
time.Sleep(2 * time.Second)
}
运行出错:fatal error: all goroutines are asleep - deadlock!