February 2020
Intermediate to advanced
412 pages
9h 36m
English
The autoConnect(int numberOfSubscribers) operator on ConnectableObservable can be quite handy. For a given ConnectableObservable<T>, calling autoConnect(int numberOfSubscribers) will return an Observable<T> that will automatically call connect() after a specified number of observers are subscribed. Since our previous example had two observers, we can streamline it by calling autoConnect(2) immediately after publish():
import io.reactivex.rxjava3.core.Observable;import java.util.concurrent.ThreadLocalRandom;public class Ch5_07 { public static void main(String[] args) { Observable<Integer> rInts = Observable.range(1, 3).map(i -> randomInt()).publish() .autoConnect(2); //Observer 1 - prints each random integer rInts.subscribe(i ...
Read now
Unlock full access