how do you drain a channel without closing it?
# coroutines
c
how do you drain a channel without closing it?
g
while + receive()
c
I was thinking more to while+poll() so that I don't suspend
g
Sounds like a bad idea for most cases
👍 1
😁 1
Why you don't want suspend?
c
because if the channel is empty, it will suspend and wait for an element, which is not what i wanted, I just want to drain the elements already in the channel.
do you think that closing the channel and instantiating a new one is better?
o
why do you need to drain the elements?
c
the receiver failed and is not interested in the elements already queued, so i restart the receiver and drain its inbox channel
o
sounds like you might want a
BroadcastChannel
, and just re-open the subscription
c
it's a fan out channel where i submit tasks which are taken from a pool of threads