Is there a way to share emitted value between cons...
# coroutines
m
Is there a way to share emitted value between consumers of the flow that's backed by the channel? Can't figure out a way for both consumers to get the same value. In attached test producer is playing ping pong between them. I hope SharedFlow will be released soon, but until it is, is there any other way? 😅
d
I think BroadcastChannel is what you’re looking for
m
it's working, thanks!
If I'm using openSubscription like that, should I somehow close it after flow is closed?
m
I think you should be able to use asFlow instead of this function. Then you don’t have the problem of closing.
👍 1
m
but now
BroadcastChannel
broke that producer produces only when there're subscribers, this is another requirement. Is there a way to have both, so shared value and a lazy producer?
m
I’m not sure whether that fixes your problem, but you could try to use send instead of offer.
m
unfortunetly it doesn't because BroadcastChannel is buffered or confloated so it won't suspend the call straight away