Recently, when reading http://blog.golang.org/pipelines I came across
this snippet of code:
case out <- n * n:
The idea is that when the channel done is closed, you return from the
function. However I had assumed that selecting on a closed channel
would be the same as though that case were missing entirely, or in
other words, that the function would never return.
After further research, it appears that what Go actually does makes
sense, though to me at least, it wasn't obvious. In the spec, in the
Receive operator section, we read:
"A receive operation on a closed channel can always proceed
immediately, yielding the element type's zero value."
In the section on the select statements, it is made clear what happens
if a channel is nil, but it does not mention what happens when
receiving from a channel that is closed. I believe it would be
helpful to add this information.
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firstname.lastname@example.org.
For more options, visit https://groups.google.com/d/optout.