速率限制可观察量

Vin*_*lho 8 rx-java

我有一个observable,它从数据库游标的快速流中生成数据.我希望以每秒x项的速率限制输出.到目前为止,我一直在使用文档中描述的Callstack阻止:

observable.map(f -> {
ratelimiter.acquire(); // configured limiter to only allow
});
Run Code Online (Sandbox Code Playgroud)

这工作正常,但出于好奇,有没有更好的方法来处理这个使用背压?

TKS

Paw*_*ski 3

使用sample(throttleLast) 运算符:

Observable<T> throttled = 
    observable.sample(1 / rate, TimeUnit.MILLISECONDS);
Run Code Online (Sandbox Code Playgroud)

http://reactivex.io/documentation/operators/sample.html

https://github.com/ReactiveX/RxJava/wiki/BackPressure

  • `sample` 会丢弃数据,我认为维尼修斯不希望这样。 (11认同)