June 2018
Intermediate to advanced
310 pages
6h 32m
English
There's a publish() method for that:
val iterator = (1..5).iterator()val subject = Observable.create<Int> { while (iterator.hasNext()) { val number = iterator.nextInt() println("P: $number") it.onNext(number) Thread.sleep(10) }}.observeOn(Schedulers.newThread()).publish()
We again create a somewhat hot Observable, but this time we specify that it will run on a separate thread with observeOn(). We also use the publish() method, which turns our Observable into ConnectableObservable.
If we simply subscribe to this type of Observable, nothing will happen. We need to tell it when to start running. We use that with the connect() method. Since the connect() method is blocking, we'll execute it from a separate thread for this example: ...
Read now
Unlock full access