BehaviorSubject

Imagine a situation when you have a stream of updates every minute. You want to display the latest value you received, then keep updating it when new data comes in. You can use ReplaySubject with a size of one. But there's also BehaviorSubject exactly for this case:

val subject = BehaviorSubject.create<Int>()

The output will be as follows:

S1 subscribes
S1 10 <= This was the most recent value, 8 and 9 are lost
S1 subscribed
S1 11 <= First update
S2 subscribes
S2 11 <= This was most recent value, 8, 9 and 10 lost
S2 subscribed
S1 12 <= As usual from here
S2 12
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.123.155