@@ -5663,8 +5663,8 @@ public final T blockingFirst(@NonNull T defaultItem) {
5663
5663
* sequence.
5664
5664
* <dl>
5665
5665
* <dt><b>Backpressure:</b></dt>
5666
- * <dd>The operator consumes the source {@code Flowable} in an unbounded manner
5667
- * (i.e., no backpressure applied to it) .</dd>
5666
+ * <dd>The operator requests {@link Flowable#bufferSize()} upfront, then 75% of this
5667
+ * amount when 75% is received .</dd>
5668
5668
* <dt><b>Scheduler:</b></dt>
5669
5669
* <dd>{@code blockingForEach} does not operate by default on a particular {@link Scheduler}.</dd>
5670
5670
* <dt><b>Error handling:</b></dt>
@@ -5676,14 +5676,57 @@ public final T blockingFirst(@NonNull T defaultItem) {
5676
5676
* @param onNext
5677
5677
* the {@link Consumer} to invoke for each item emitted by the {@code Flowable}
5678
5678
* @throws RuntimeException
5679
- * if an error occurs
5679
+ * if an error occurs; {@link Error}s and {@link RuntimeException}s are rethrown
5680
+ * as they are, checked {@link Exception}s are wrapped into {@code RuntimeException}s
5680
5681
* @see <a href="http://reactivex.io/documentation/operators/subscribe.html">ReactiveX documentation: Subscribe</a>
5681
5682
* @see #subscribe(Consumer)
5683
+ * @see #blockingForEach(Consumer, int)
5682
5684
*/
5683
- @BackpressureSupport(BackpressureKind.UNBOUNDED_IN )
5685
+ @BackpressureSupport(BackpressureKind.FULL )
5684
5686
@SchedulerSupport(SchedulerSupport.NONE)
5685
5687
public final void blockingForEach(@NonNull Consumer<? super T> onNext) {
5686
- Iterator<T> it = blockingIterable().iterator();
5688
+ blockingForEach(onNext, bufferSize());
5689
+ }
5690
+
5691
+ /**
5692
+ * Consumes the upstream {@code Flowable} in a blocking fashion and invokes the given
5693
+ * {@code Consumer} with each upstream item on the <em>current thread</em> until the
5694
+ * upstream terminates.
5695
+ * <p>
5696
+ * <img width="640" height="330" src="https://github.com/ReactiveX/RxJava/wiki/images/rx-operators/B.forEach.png" alt="">
5697
+ * <p>
5698
+ * <em>Note:</em> the method will only return if the upstream terminates or the current
5699
+ * thread is interrupted.
5700
+ * <p>
5701
+ * This method executes the {@code Consumer} on the current thread while
5702
+ * {@link #subscribe(Consumer)} executes the consumer on the original caller thread of the
5703
+ * sequence.
5704
+ * <dl>
5705
+ * <dt><b>Backpressure:</b></dt>
5706
+ * <dd>The operator requests the given {@code prefetch} amount upfront, then 75% of this
5707
+ * amount when 75% is received.</dd>
5708
+ * <dt><b>Scheduler:</b></dt>
5709
+ * <dd>{@code blockingForEach} does not operate by default on a particular {@link Scheduler}.</dd>
5710
+ * <dt><b>Error handling:</b></dt>
5711
+ * <dd>If the source signals an error, the operator wraps a checked {@link Exception}
5712
+ * into {@link RuntimeException} and throws that. Otherwise, {@code RuntimeException}s and
5713
+ * {@link Error}s are rethrown as they are.</dd>
5714
+ * </dl>
5715
+ *
5716
+ * @param onNext
5717
+ * the {@link Consumer} to invoke for each item emitted by the {@code Flowable}
5718
+ * @param bufferSize
5719
+ * the number of items to prefetch upfront, then 75% of it after 75% received
5720
+ * @throws RuntimeException
5721
+ * if an error occurs; {@link Error}s and {@link RuntimeException}s are rethrown
5722
+ * as they are, checked {@link Exception}s are wrapped into {@code RuntimeException}s
5723
+ * @see <a href="http://reactivex.io/documentation/operators/subscribe.html">ReactiveX documentation: Subscribe</a>
5724
+ * @see #subscribe(Consumer)
5725
+ */
5726
+ @BackpressureSupport(BackpressureKind.FULL)
5727
+ @SchedulerSupport(SchedulerSupport.NONE)
5728
+ public final void blockingForEach(@NonNull Consumer<? super T> onNext, int bufferSize) {
5729
+ Iterator<T> it = blockingIterable(bufferSize).iterator();
5687
5730
while (it.hasNext()) {
5688
5731
try {
5689
5732
onNext.accept(it.next());
0 commit comments