I have the requirement of being able to drain a channel, i.e. make sure 
that downstream processes all data currently being sent. One possible 
pattern is something like

for{
select{
case <-q.data:
default:
}
}

where the default branch could indicate that channel has been drained. My 
concern is, that this would create a busy loop on the default branch even 
when not trying to drain the channel.

I could use an atomic for checking if work should be done in default (i.e. 
signal channel has been drained).

Would that still busy-loop? Are there better patterns?

Cheers,
Andi

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/4887e28d-bcfb-4f49-9450-00e56e00be55n%40googlegroups.com.

Reply via email to