No. The complete select+code blocks is not atomic, so the select may
see that closedchan is not closed, execute the default case, but in the
mean time closedchan has been closed by someone else. Bang!

On Mon, 2017-11-06 at 16:59 -0800, Albert Tedja wrote:
> Since closing an already closed channel creates a panic, does this
> mean 
> then I can do this to make sure that the channel is closed only once?
> 
> 
> select {
>     case <- closedchan:
>     default:
>         close(closedchan)
> }



-- 
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 golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to