Hello! I have a question about channels/flow: I’d ...
# coroutines
j
Hello! I have a question about channels/flow: I’d like to emit events and be able to cancel subscription and later have another instance subscribe to the same channel (with the events accumulated when there is no subscriber). My understanding is that this can be achieved with a Channel with unlimited capacity, but the problem I face is that when the subscriber’s scope is cancelled the channel is closed. If I use GlobalScope it does not occur, but then it is my understanding that it is not unsubscribing. So, how can I have a channel that does not get closed when I unsubscribe?
o
it sounds like you do not want to actually close the channel, but use something like
BroadcastChannel
which has a separate subscription lifecycle
j
Sorry, I couldn’t try it until now. The problem I face with a Broadcast channel is that it does not accumulate events. So, if there is no subscriber the event is lost (I use consumeEach at the receiver and BroadcastChannel<T>(100) with send at the emitter