June 2018
Intermediate to advanced
310 pages
6h 32m
English
In addition to PublishSubject, which we discussed in the previous section, there are other subjects available. To understand how ReplaySubject works, let's see first the following example with PublishSubject:
val list = (8..23).toList() // Some non trivial numbersval iterator = list.iterator()val o = Observable.intervalRange(0, list.size.toLong(), 0, 10, TimeUnit.MILLISECONDS).map { iterator.next()}.publish()val subject = PublishSubject.create<Int>()o.subscribe(subject)o.connect() // Start publishingThread.sleep(20)println("S1 subscribes") subject.subscribe { println("S1 $it") } println("S1 subscribed") Thread.sleep(10) println("S2 subscribes") subject.subscribe { println("S2 $it") } println("S2 subscribed") Thread.sleep(1000) ...
Read now
Unlock full access