February 2020
Intermediate to advanced
412 pages
9h 36m
English
Similar to Observable.combineLatest(), but not exactly the same, is the withLatestFrom() operator. This will map each T emission with the latest values from other observables and combine them, but it will only take one emission from each of the other observables:
import io.reactivex.rxjava3.core.Observable;import java.util.concurrent.TimeUnit;public class Ch4_16 { public static void main(String[] args) { Observable<Long> source1 = Observable.interval(300, TimeUnit.MILLISECONDS); Observable<Long> source2 = Observable.interval(1, TimeUnit.SECONDS); source2.withLatestFrom(source1, (l1, l2) -> "SOURCE 2: " + l1 + " SOURCE 1: " + l2) .subscribe(System.out::println); sleep(3000); }}
The output is as follows:
SOURCE 2: 0 SOURCE ...
Read now
Unlock full access