February 2020
Intermediate to advanced
412 pages
9h 36m
English
The throttleLast() operator (another name for the same operator is sample()) emits only the last item at a fixed time interval. Modify the preceding example by adding throttleLast() at 1-second intervals, as shown here:
Observable.concat(source1, source2, source3) .throttleLast(1, TimeUnit.SECONDS) .subscribe(System.out::println);
The output will change as follows:
SOURCE 1: 900SOURCE 2: 900SOURCE 3: 2000
As you can see, the last emission at every 1-second interval was all that got through. This effectively samples emissions by dipping into the stream on a timer and pulling out the latest one.
If you throttle more liberally at a larger time interval, you will get fewer emissions as this effectively reduces the ...
Read now
Unlock full access