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