February 2020
Intermediate to advanced
412 pages
9h 36m
English
A slight variant of onBackpressureBuffer() is the onBackPressureLatest() operator. This retains the latest value from the source while the downstream is busy. Once the downstream is free to process more, it provides the latest value. Any previous values emitted during this busy period are lost. The following is an example that demonstrates this behavior:
import io.reactivex.rxjava3.core.Flowable;import io.reactivex.rxjava3.schedulers.Schedulers;public class Ch8_15 { public static void main(String[] args) { Flowable.interval(1, TimeUnit.MILLISECONDS) .onBackpressureLatest() .observeOn(Schedulers.io()) .subscribe(i -> { sleep(5); System.out.println(i); }); sleep(5000); }}
The output is as follows:
... 122 123 124 125 ...
Read now
Unlock full access