https://kotlinlang.org logo
#coroutines
Title
# coroutines
c

coder82

08/20/2019, 11:59 AM
how do you drain a channel without closing it?
g

gildor

08/20/2019, 12:41 PM
while + receive()
c

coder82

08/20/2019, 12:46 PM
I was thinking more to while+poll() so that I don't suspend
g

gildor

08/20/2019, 1:34 PM
Sounds like a bad idea for most cases
👍 1
😁 1
Why you don't want suspend?
c

coder82

08/20/2019, 7:41 PM
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

octylFractal

08/20/2019, 9:18 PM
why do you need to drain the elements?
c

coder82

08/20/2019, 9:41 PM
the receiver failed and is not interested in the elements already queued, so i restart the receiver and drain its inbox channel
o

octylFractal

08/20/2019, 9:47 PM
sounds like you might want a
BroadcastChannel
, and just re-open the subscription
c

coder82

08/21/2019, 12:08 PM
it's a fan out channel where i submit tasks which are taken from a pool of threads
5 Views