Re: [go-nuts] A way to detect closed channel

2017-11-07 Thread Daniel Skinner
Instead of recover, I'd consider simply writing to the channel. https://play.golang.org/p/ShoadwrwTQ If it has to be a close, pass in additional state to close only once. https://play.golang.org/p/pwO3JF60Cr On Tue, Nov 7, 2017 at 3:32 AM roger peppe wrote: > On 7

Re: [go-nuts] A way to detect closed channel

2017-11-07 Thread Dave Cheney
gross. -- 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.

Re: [go-nuts] A way to detect closed channel

2017-11-07 Thread Steven Hartland
If you're using it as a signal to trigger only on close and not sending any data, you should use chan struct{}, the reason for this is is that the empty struct consumes zero storage . Also there is a multi-valued assignment form of the

Re: [go-nuts] A way to detect closed channel

2017-11-07 Thread roger peppe
On 7 November 2017 at 00:59, Albert Tedja wrote: > So, I just found out that closed channels always yield the zero value. That > means, a closed channel inside a select statement seems to always be > guaranteed to be executed. > > Since closing an already closed channel

Re: [go-nuts] A way to detect closed channel

2017-11-06 Thread Albert Tedja
That makes sense. If multiple goroutines are calling that select block, one or more could be attempting to close it. Okay, nevermind then. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving

Re: [go-nuts] A way to detect closed channel

2017-11-06 Thread Daniel Skinner
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

Re: [go-nuts] A way to detect closed channel

2017-11-06 Thread Dan Kortschak
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

[go-nuts] A way to detect closed channel

2017-11-06 Thread Albert Tedja
So, I just found out that closed channels always yield the zero value. That means, a closed channel inside a select statement seems to always be guaranteed to be executed. Since closing an already closed channel creates a panic, does this mean then I can do this to make sure that the channel