4 ms·
> but I think "<- true" looks nicer than "<- struct{} {}" And what looks even better: defer close(doneChannel) (it's also syntactically correct -- you ca
by dlsspy 13y ago
> but I think "<- true" looks nicer than "<- struct{} {}"
And what looks even better:
defer close(doneChannel)
(it's also syntactically correct -- you ca't just have a defer block without a function invocation)
- lobster_johnson 13y agoClosing the channel is fine, I suppose, although the supervising goroutine now looks a bit odd: select { case _, _ := <- doneChannel // Other goroutine is now done It's so implicit that you pretty much have to add a comment to the effect of "this will trigger when the channel is closed", whereas the "case <- doneChannel" is so obvious it doesn't need explaining. Also, I rather prefer the supervising goroutine to "own" the channel, so it should be the one to close it. > you ca't just have a defer block without a function invocation Yeah, I was not thinking Go there for a moment. Should have been "defer func() { doneChannel <- true }".
- redbad 13y ago> the supervising goroutine now looks a bit odd: This is totally valid: select { case <-doneChannel: //