我使用RxJava观察几个按钮上的点击。
这些订阅将在一个对象上调用不同的函数,这需要几毫秒。这些功能是同步的。
问题是,当按下太多按钮时,我会得到一个背压异常。对我来说有用的是丢弃几个输入(最好是oldes)。 RxJava可以吗?
答案 0 :(得分:5)
答案 1 :(得分:0)
对于RxJava 3,您可以使用新的Flowable概念:
observable.toFlowable(BackpressureStrategy.LATEST)
您可以选择不同的策略:
/**
* OnNext events are written without any buffering or dropping.
* Downstream has to deal with any overflow.
* <p>Useful when one applies one of the custom-parameter onBackpressureXXX operators.
*/
MISSING,
/**
* Signals a MissingBackpressureException in case the downstream can't keep up.
*/
ERROR,
/**
* Buffers <em>all</em> onNext values until the downstream consumes it.
*/
BUFFER,
/**
* Drops the most recent onNext value if the downstream can't keep up.
*/
DROP,
/**
* Keeps only the latest onNext value, overwriting any previous value if the
* downstream can't keep up.
*/
LATEST