June 2017
Intermediate to advanced
400 pages
8h 44m
English
The throttleLast() operator (which is aliased as sample()) will only emit the last item at a fixed time interval. Modify your earlier example to use throttleLast() at 1-second intervals, as shown here:
Observable.concat(source1, source2, source3) .throttleLast(1, TimeUnit.SECONDS) .subscribe(System.out::println);
The output is as follows:
SOURCE 1: 900SOURCE 2: 900SOURCE 3: 2000
If you study the output, you can see that 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 want to throttle more liberally at larger time intervals, you will get fewer emissions as this effectively reduces ...
Read now
Unlock full access