3 ms·
I think you could do which I'd argue is more idiomatic ( for { if _, ok := <- doneCh; ok { break } select { case thing := <
by schrodinger 5y ago
I think you could do which I'd argue is more idiomatic (
for {
if _, ok := <- doneCh; ok {
break
}
select {
case thing := <-thingCh:
// ... long-running operation
case <-time.After(5*time.Second):
return fmt.Errorf("timeout")
}
}
Which goes along w/ https://github.com/golang/go/wiki/CodeReviewComments#indent-error-flow https://github.com/golang/go/wiki/CodeReviewComments#indent-... of "Indent error flow".
edit: nvm, your break would be blocked until one of the other channels produced a value. you'd need to check for the doneCh redundantly again in the select.