@@ -12546,7 +12546,7 @@ public final Flowable<T> onBackpressureBuffer(int capacity, boolean delayError)
12546
12546
@NonNull
12547
12547
public final Flowable<T> onBackpressureBuffer(int capacity, boolean delayError, boolean unbounded) {
12548
12548
ObjectHelper.verifyPositive(capacity, "capacity");
12549
- return RxJavaPlugins.onAssembly(new FlowableOnBackpressureBuffer<>(this, capacity, unbounded, delayError, Functions.EMPTY_ACTION));
12549
+ return RxJavaPlugins.onAssembly(new FlowableOnBackpressureBuffer<>(this, capacity, unbounded, delayError, Functions.EMPTY_ACTION, Functions.emptyConsumer() ));
12550
12550
}
12551
12551
12552
12552
/**
@@ -12577,6 +12577,7 @@ public final Flowable<T> onBackpressureBuffer(int capacity, boolean delayError,
12577
12577
* @throws NullPointerException if {@code onOverflow} is {@code null}
12578
12578
* @throws IllegalArgumentException if {@code capacity} is non-positive
12579
12579
* @see <a href="http://reactivex.io/documentation/operators/backpressure.html">ReactiveX operators documentation: backpressure operators</a>
12580
+ * @see #onBackpressureBuffer(int, boolean, boolean, Action, Consumer)
12580
12581
* @since 1.1.0
12581
12582
*/
12582
12583
@CheckReturnValue
@@ -12587,7 +12588,51 @@ public final Flowable<T> onBackpressureBuffer(int capacity, boolean delayError,
12587
12588
@NonNull Action onOverflow) {
12588
12589
Objects.requireNonNull(onOverflow, "onOverflow is null");
12589
12590
ObjectHelper.verifyPositive(capacity, "capacity");
12590
- return RxJavaPlugins.onAssembly(new FlowableOnBackpressureBuffer<>(this, capacity, unbounded, delayError, onOverflow));
12591
+ return RxJavaPlugins.onAssembly(new FlowableOnBackpressureBuffer<>(this, capacity, unbounded, delayError, onOverflow, Functions.emptyConsumer()));
12592
+ }
12593
+
12594
+ /**
12595
+ * Buffers an optionally unlimited number of items from the current {@code Flowable} and allows it to emit as fast it can while allowing the
12596
+ * downstream to consume the items at its own place.
12597
+ * If {@code unbounded} is {@code true}, the resulting {@code Flowable} will signal a
12598
+ * {@link MissingBackpressureException} via {@code onError} as soon as the buffer's capacity is exceeded, dropping all undelivered
12599
+ * items, canceling the flow and calling the {@code onOverflow} action.
12600
+ * <p>
12601
+ * <img width="640" height="300" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/bp.obp.buffer.v3.png" alt="">
12602
+ * <dl>
12603
+ * <dt><b>Backpressure:</b></dt>
12604
+ * <dd>The operator honors backpressure from downstream and consumes the current {@code Flowable} in an unbounded
12605
+ * manner (i.e., not applying backpressure to it).</dd>
12606
+ * <dt><b>Scheduler:</b></dt>
12607
+ * <dd>{@code onBackpressureBuffer} does not operate by default on a particular {@link Scheduler}.</dd>
12608
+ * </dl>
12609
+ *
12610
+ * @param capacity number of slots available in the buffer.
12611
+ * @param delayError
12612
+ * if {@code true}, an exception from the current {@code Flowable} is delayed until all buffered elements have been
12613
+ * consumed by the downstream; if {@code false}, an exception is immediately signaled to the downstream, skipping
12614
+ * any buffered element
12615
+ * @param unbounded
12616
+ * if {@code true}, the capacity value is interpreted as the internal "island" size of the unbounded buffer
12617
+ * @param onOverflow action to execute if an item needs to be buffered, but there are no available slots.
12618
+ * @param onDropped the {@link Consumer} to be called with the item that could not be buffered due to capacity constraints.
12619
+ * @return the new {@code Flowable} instance
12620
+ * @throws NullPointerException if {@code onOverflow} or {@code onDropped} is {@code null}
12621
+ * @throws IllegalArgumentException if {@code capacity} is non-positive
12622
+ * @see <a href="http://reactivex.io/documentation/operators/backpressure.html">ReactiveX operators documentation: backpressure operators</a>
12623
+ * @since 3.1.7
12624
+ */
12625
+ @CheckReturnValue
12626
+ @NonNull
12627
+ @BackpressureSupport(BackpressureKind.SPECIAL)
12628
+ @SchedulerSupport(SchedulerSupport.NONE)
12629
+ @Experimental
12630
+ public final Flowable<T> onBackpressureBuffer(int capacity, boolean delayError, boolean unbounded,
12631
+ @NonNull Action onOverflow, @NonNull Consumer<? super T> onDropped) {
12632
+ Objects.requireNonNull(onOverflow, "onOverflow is null");
12633
+ Objects.requireNonNull(onDropped, "onDropped is null");
12634
+ ObjectHelper.verifyPositive(capacity, "capacity");
12635
+ return RxJavaPlugins.onAssembly(new FlowableOnBackpressureBuffer<>(this, capacity, unbounded, delayError, onOverflow, onDropped));
12591
12636
}
12592
12637
12593
12638
/**
@@ -12653,6 +12698,7 @@ public final Flowable<T> onBackpressureBuffer(int capacity, @NonNull Action onOv
12653
12698
* @throws NullPointerException if {@code onOverflow} or {@code overflowStrategy} is {@code null}
12654
12699
* @throws IllegalArgumentException if {@code capacity} is non-positive
12655
12700
* @see <a href="http://reactivex.io/documentation/operators/backpressure.html">ReactiveX operators documentation: backpressure operators</a>
12701
+ * @see #onBackpressureBuffer(long, Action, BackpressureOverflowStrategy)
12656
12702
* @since 2.0
12657
12703
*/
12658
12704
@CheckReturnValue
@@ -12662,9 +12708,55 @@ public final Flowable<T> onBackpressureBuffer(int capacity, @NonNull Action onOv
12662
12708
public final Flowable<T> onBackpressureBuffer(long capacity, @Nullable Action onOverflow, @NonNull BackpressureOverflowStrategy overflowStrategy) {
12663
12709
Objects.requireNonNull(overflowStrategy, "overflowStrategy is null");
12664
12710
ObjectHelper.verifyPositive(capacity, "capacity");
12665
- return RxJavaPlugins.onAssembly(new FlowableOnBackpressureBufferStrategy<>(this, capacity, onOverflow, overflowStrategy));
12711
+ return RxJavaPlugins.onAssembly(new FlowableOnBackpressureBufferStrategy<>(this, capacity, onOverflow, overflowStrategy, null ));
12666
12712
}
12667
12713
12714
+ /**
12715
+ * Buffers an optionally unlimited number of items from the current {@code Flowable} and allows it to emit as fast it can while allowing the
12716
+ * downstream to consume the items at its own place.
12717
+ * The resulting {@code Flowable} will behave as determined by {@code overflowStrategy} if the buffer capacity is exceeded:
12718
+ * <ul>
12719
+ * <li>{@link BackpressureOverflowStrategy#ERROR} (default) will call {@code onError} dropping all undelivered items,
12720
+ * canceling the source, and notifying the producer with {@code onOverflow}. </li>
12721
+ * <li>{@link BackpressureOverflowStrategy#DROP_LATEST} will drop any new items emitted by the producer while
12722
+ * the buffer is full, without generating any {@code onError}. Each drop will, however, invoke {@code onOverflow}
12723
+ * to signal the overflow to the producer.</li>
12724
+ * <li>{@link BackpressureOverflowStrategy#DROP_OLDEST} will drop the oldest items in the buffer in order to make
12725
+ * room for newly emitted ones. Overflow will not generate an {@code onError}, but each drop will invoke
12726
+ * {@code onOverflow} to signal the overflow to the producer.</li>
12727
+ * </ul>
12728
+ *
12729
+ * <p>
12730
+ * <img width="640" height="300" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/bp.obp.buffer.v3.png" alt="">
12731
+ * <dl>
12732
+ * <dt><b>Backpressure:</b></dt>
12733
+ * <dd>The operator honors backpressure from downstream and consumes the current {@code Flowable} in an unbounded
12734
+ * manner (i.e., not applying backpressure to it).</dd>
12735
+ * <dt><b>Scheduler:</b></dt>
12736
+ * <dd>{@code onBackpressureBuffer} does not operate by default on a particular {@link Scheduler}.</dd>
12737
+ * </dl>
12738
+ *
12739
+ * @param capacity number of slots available in the buffer.
12740
+ * @param onOverflow action to execute if an item needs to be buffered, but there are no available slots, {@code null} is allowed.
12741
+ * @param overflowStrategy how should the resulting {@code Flowable} react to buffer overflows, {@code null} is not allowed.
12742
+ * @param onDropped the {@link Consumer} to be called with the item that could not be buffered due to capacity constraints.
12743
+ * @return the new {@code Flowable} instance
12744
+ * @throws NullPointerException if {@code onOverflow}, {@code overflowStrategy} or {@code onDropped} is {@code null}
12745
+ * @throws IllegalArgumentException if {@code capacity} is non-positive
12746
+ * @see <a href="http://reactivex.io/documentation/operators/backpressure.html">ReactiveX operators documentation: backpressure operators</a>
12747
+ * @since 3.1.7
12748
+ */
12749
+ @CheckReturnValue
12750
+ @NonNull
12751
+ @BackpressureSupport(BackpressureKind.SPECIAL)
12752
+ @SchedulerSupport(SchedulerSupport.NONE)
12753
+ @Experimental
12754
+ public final Flowable<T> onBackpressureBuffer(long capacity, @Nullable Action onOverflow, @NonNull BackpressureOverflowStrategy overflowStrategy, @NonNull Consumer<? super T> onDropped) {
12755
+ Objects.requireNonNull(overflowStrategy, "overflowStrategy is null");
12756
+ Objects.requireNonNull(onDropped, "onDropped is null");
12757
+ ObjectHelper.verifyPositive(capacity, "capacity");
12758
+ return RxJavaPlugins.onAssembly(new FlowableOnBackpressureBufferStrategy<>(this, capacity, onOverflow, overflowStrategy, onDropped));
12759
+ }
12668
12760
/**
12669
12761
* Drops items from the current {@code Flowable} if the downstream is not ready to receive new items (indicated
12670
12762
* by a lack of {@link Subscription#request(long)} calls from it).
0 commit comments