Setting a channel variable to nil simply sets the variable to nil, while leaving the channel it had previously referred to initialized.
It's the same as setting any other variable to nil.
If there are other references to the channel, you could still access it. If there are not, it will be garbage collected.
Additionally, nil
versus closed channels behave differently when writing or reading. From Dave Cheney's blog post, Channel Axioms, which I recommend reading in its entirety:
- A send to a nil channel blocks forever
- A receive from a nil channel blocks forever
- A send to a closed channel panics
- A receive from a closed channel returns the zero value immediately