Is there any way to match a `BehaviorSubject` with...
# coroutines
s
Is there any way to match a
BehaviorSubject
with a
BroadcastChannel
?
ConflatedBroadcastChannel
allows for the loss of events after subscription, while
BehaviorSubject
guarantees all events to be delivered. I've tried swapping to an
ArrayBroadcastChannel
to help ensure all events are delivered, but I have no way to ensure that the current value is delivered to a new subscriber upon a new subscription being opened. Any suggestions?
j
it's indeed
ConflatedBroadcastChannel
or so the doc says,
BheaviourSubject
only delivers the last value, the rest of them get lost
for the new subscriptors I mean
s
@fuegolop That's incorrect. Only the events before I subscribe to the BehaviorSubject are lost. If I call
Copy code
behaviorSubject.onNext(1)
behaviorSubject.onNext(2)
behaviorSubject.onNext(3)
behaviorSubject.onNext(4)
I'm guaranteed to receive all 4 events to all subscribers. If I call
Copy code
conflatedBroadcastChannel.send(1)
conflatedBroadcastChannel.send(2)
conflatedBroadcastChannel.send(3)
conflatedBroadcastChannel.send(4)
I'm only guaranteed to receive the 4th event on my subscribers. It's very likely that with the above code, I'll actually only receive the 1st and 4th event, and the 2nd and 3rd event will be lost. In fact, that's what I'm seeing consistently in my code running only on my Android main thread.