Need not close every channel

You don’t need to close channel after using it, and it can be recycled automatically by the garbage collector. The following quote is from The Go Programming Language: You needn’t close every channel when you’ve finished with it. It’s only necessary to close a channel when it is important to tell the receiving goroutines that all data have been sent. A channel that the garbage collector determines to be unreachable will have its resources reclaimed whether or not it is closed. [Read More]

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]