June 2018
Intermediate to advanced
310 pages
6h 32m
English
Throttling on the consumer side is similar to dropping on the producer side. But it can be applied not only to Flowable, but also to Observable. You specify the time interval, and each time get only one element, either the first or last one, in that interval:
val o = PublishSubject.intervalRange(8L, 15L, 0L, 100L, TimeUnit.MILLISECONDS).publish()o.throttleFirst(280L, TimeUnit.MILLISECONDS).subscribe { println(it)}o.buffer(280L, TimeUnit.MILLISECONDS).subscribe { println(it)}o.connect()Thread.sleep(100 * 15)
Execute this example a few times and you will see that you get different results. Throttling is highly sensitive to timing.
throttleFirst() outputs [8, 11, 15, 17, 21] because it received the following windows:
8[8, 9, 10] ...
Read now
Unlock full access