February 2020
Intermediate to advanced
412 pages
9h 36m
English
We have used the ConnectableObservable earlier in Chapter 2, Observable and Observer. Remember how a cold Observable, such as the one created by Observable.range(), regenerates emissions for each subscribed Observer? Let's take a look at the following code:
import io.reactivex.rxjava3.core.Observable;public class Ch5_01 { public static void main(String[] args) { Observable<Integer> ints = Observable.range(1, 3); ints.subscribe(i -> System.out.println("Observer One: " + i)); ints.subscribe(i -> System.out.println("Observer Two: " + i)); }}
The output obtained is as follows:
Observer One: 1Observer One: 2Observer One: 3Observer Two: 1Observer Two: 2Observer Two: 3
Here, Observer One received all three emissions and ...
Read now
Unlock full access