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: 1
Observer One: 2
Observer One: 3
Observer Two: 1
Observer Two: 2
Observer Two: 3
Here, Observer One received all three emissions and called onComplete(). After that, Observer Two received the three emissions...