nil channel VS closed channel
The zero value of channel type is nil, and the send and receive operations on a nil channel will always block. Check the following example:
package main import "fmt" func main() { var ch chan int go func(c chan int) { for v := range c { fmt.Println(v) } }(ch) ch <- 1 } The running result is like this:
fatal error: all goroutines are asleep - deadlock!
goroutine 1 [chan send (nil chan)]: main.
[Read More]