meaning, don't call that select+code block from multiple goroutines. If on the other-hand that block is always called from the same goroutine, then it will do what you want, but that may be a slippery slope depending on what you're writing.
On Mon, Nov 6, 2017 at 7:33 PM Dan Kortschak <dan.kortsc...@adelaide.edu.au> wrote: > 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. > -- 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.