A Channel’s `.invokeOnClose { }` documentation sta...
# coroutines
c
A Channel’s
.invokeOnClose { }
documentation states that “The handler is invoked when `Channel.isClosedForSend' starts to return true." Is there any equivalent mechanism for being notified when
Channel.isClosedForReceive
starts to return true?
In other words, I need a way to close a channel and then be notified once all buffered elements in the channel have been consumed, thus signifying that the channel is closed AND fully drained
s
If you can pass a
Flow
instead of a
Channel
, you could use
onCompletion
c
I specifically need a hot Channel because I’m using it as an async queue, and am working with lower-level coroutine stuff than Flows
k
You can make a flow how with something like
Channel.recieveAsFlow
Or the
channelFlow
and
callbackFlow
builders
c
I think
Channel.receiveAsFlow().onCompletion
might to do what I need. Thanks y’all!
k
Please note that there’s
recieveAsFlow
and
consumeAsflow
you should look at the docs for each and use whichever function is proper for your use case.