1

我使用 RxJava 来观察点击几个按钮。

这些订阅将在一个对象上调用不同的函数,这需要几毫秒。这些功能是同步的。

问题是当按下太多按钮时,我会遇到背压异常。对我有用的是放弃几个输入(最好是旧的)。RxJava 有可能吗?

4

2 回答 2

5

这是onBackPressureDrop()用于:

指示发出项目的速度快于其观察者可以消耗它们的 Observable 丢弃而不是发射其观察者不准备观察的那些项目。

onBackPressureDrop()

于 2015-12-14T23:26:41.257 回答
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
于 2019-10-03T08:27:29.843 回答