June 2018
Intermediate to advanced
310 pages
6h 32m
English
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 subscribesS1 10 <= This was the most recent value, 8 and 9 are lostS1 subscribedS1 11 <= First update S2 subscribesS2 11 <= This was most recent value, 8, 9 and 10 lostS2 subscribedS1 12 <= As usual from hereS2 12
Read now
Unlock full access