June 2017
Intermediate to advanced
400 pages
8h 44m
English
A slight variant of onBackpressureBuffer() is onBackPressureLatest(). This will retain the latest value from the source while the downstream is busy, and once the downstream is free to process more, it will provide the latest value. Any previous values emitted during this busy period will be lost:
import io.reactivex.Flowable; import io.reactivex.schedulers.Schedulers;import java.util.concurrent.TimeUnit;public class Launcher { 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); } public static void sleep(long millis) { try { Thread.sleep(millis); } catch (InterruptedException ...Read now
Unlock full access