SharedFlow
has just been introduced in coroutines 1.4.0-M1, and it is meant to replace all BroadcastChannel
implementations (as stated in the design issue decription).
I have a use case where I use a BroadcastChannel
to represent incoming web socket frames, so that multiple listeners can "subscribe" to the frames.
The problem I have when I move to a SharedFlow
is that I can't "end" the flow when I receive a close frame, or an upstream error (which I would like to do to inform all subscribers that the flow is over).
How can I make all subscriptions terminate when I want to effectively "close" the SharedFlow
?
Is there a way to tell the difference between normal closure and closure with exception? (like channels)
If MutableSharedFlow
doesn't allow to convey the end of the flow to subscribers, what is the alternative if BroadcastChannel
gets deprecated/removed?