rx java - Rate limiting observables -
i have observable produces info fast stream database cursor. i'm looking throttle output on rate of x items per second. far i've been using callstack blocking described on docs:
observable.map(f -> { ratelimiter.acquire(); // configured limiter allow });
this working fine, out of curiosity there improve way handle using backpressure?
tks
use sample
(throttlelast) operator:
observable<t> throttled = observable.sample(1 / rate, timeunit.milliseconds);
http://reactivex.io/documentation/operators/sample.html
https://github.com/reactivex/rxjava/wiki/backpressure
rx-java
No comments:
Post a Comment