3 ms·
In Go, sending a value through a closed channel panics the program, and receiving a value from a closed channel immediately returns the zero value for the chann
by tene 5y ago
In Go, sending a value through a closed channel panics the program, and receiving a value from a closed channel immediately returns the zero value for the channel (and a false, if you use the two-return-values form of the receive operator).
There's no difference in what side closes the channel, I think, just in how a closed channel behaves when you try to send or receive on it.
Personally, I think it's terrifying that the "easy" option just lies to you instead of crashing the program, but I kind of see how it fits with some of Go's other design decisions that I'd also have made differently (Option/Result instead of pervasive nullability).