|
26 | 26 | import io.reactivex.rxjava3.internal.functions.*;
|
27 | 27 | import io.reactivex.rxjava3.internal.fuseable.*;
|
28 | 28 | import io.reactivex.rxjava3.internal.jdk8.*;
|
29 |
| -import io.reactivex.rxjava3.internal.observers.BlockingMultiObserver; |
| 29 | +import io.reactivex.rxjava3.internal.observers.*; |
30 | 30 | import io.reactivex.rxjava3.internal.operators.flowable.*;
|
31 | 31 | import io.reactivex.rxjava3.internal.operators.maybe.*;
|
32 | 32 | import io.reactivex.rxjava3.internal.operators.mixed.*;
|
@@ -2475,6 +2475,135 @@ public final T blockingGet(@NonNull T defaultValue) {
|
2475 | 2475 | return observer.blockingGet(defaultValue);
|
2476 | 2476 | }
|
2477 | 2477 |
|
| 2478 | + /** |
| 2479 | + * Subscribes to the current {@code Maybe} and <em>blocks the current thread</em> until it terminates. |
| 2480 | + * <p> |
| 2481 | + * <img width="640" height="238" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Maybe.blockingSubscribe.png" alt=""> |
| 2482 | + * <dl> |
| 2483 | + * <dt><b>Scheduler:</b></dt> |
| 2484 | + * <dd>{@code blockingSubscribe} does not operate by default on a particular {@link Scheduler}.</dd> |
| 2485 | + * <dt><b>Error handling:</b></dt> |
| 2486 | + * <dd>If the current {@code Maybe} signals an error, |
| 2487 | + * the {@link Throwable} is routed to the global error handler via {@link RxJavaPlugins#onError(Throwable)}. |
| 2488 | + * If the current thread is interrupted, an {@link InterruptedException} is routed to the same global error handler. |
| 2489 | + * </dd> |
| 2490 | + * </dl> |
| 2491 | + * @since 3.0.0 |
| 2492 | + * @see #blockingSubscribe(Consumer) |
| 2493 | + * @see #blockingSubscribe(Consumer, Consumer) |
| 2494 | + * @see #blockingSubscribe(Consumer, Consumer, Action) |
| 2495 | + */ |
| 2496 | + @SchedulerSupport(SchedulerSupport.NONE) |
| 2497 | + public final void blockingSubscribe() { |
| 2498 | + blockingSubscribe(Functions.emptyConsumer(), Functions.ERROR_CONSUMER, Functions.EMPTY_ACTION); |
| 2499 | + } |
| 2500 | + |
| 2501 | + /** |
| 2502 | + * Subscribes to the current {@code Maybe} and calls given {@code onSuccess} callback on the <em>current thread</em> |
| 2503 | + * when it completes normally. |
| 2504 | + * <p> |
| 2505 | + * <img width="640" height="245" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Maybe.blockingSubscribe.c.png" alt=""> |
| 2506 | + * <dl> |
| 2507 | + * <dt><b>Scheduler:</b></dt> |
| 2508 | + * <dd>{@code blockingSubscribe} does not operate by default on a particular {@link Scheduler}.</dd> |
| 2509 | + * <dt><b>Error handling:</b></dt> |
| 2510 | + * <dd>If either the current {@code Maybe} signals an error or {@code onSuccess} throws, |
| 2511 | + * the respective {@link Throwable} is routed to the global error handler via {@link RxJavaPlugins#onError(Throwable)}. |
| 2512 | + * If the current thread is interrupted, an {@link InterruptedException} is routed to the same global error handler. |
| 2513 | + * </dd> |
| 2514 | + * </dl> |
| 2515 | + * @param onSuccess the {@link Consumer} to call if the current {@code Maybe} succeeds |
| 2516 | + * @throws NullPointerException if {@code onSuccess} is {@code null} |
| 2517 | + * @since 3.0.0 |
| 2518 | + * @see #blockingSubscribe(Consumer, Consumer) |
| 2519 | + * @see #blockingSubscribe(Consumer, Consumer, Action) |
| 2520 | + */ |
| 2521 | + @SchedulerSupport(SchedulerSupport.NONE) |
| 2522 | + public final void blockingSubscribe(@NonNull Consumer<? super T> onSuccess) { |
| 2523 | + blockingSubscribe(onSuccess, Functions.ERROR_CONSUMER, Functions.EMPTY_ACTION); |
| 2524 | + } |
| 2525 | + |
| 2526 | + /** |
| 2527 | + * Subscribes to the current {@code Maybe} and calls the appropriate callback on the <em>current thread</em> |
| 2528 | + * when it terminates. |
| 2529 | + * <p> |
| 2530 | + * <img width="640" height="256" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Maybe.blockingSubscribe.cc.png" alt=""> |
| 2531 | + * <dl> |
| 2532 | + * <dt><b>Scheduler:</b></dt> |
| 2533 | + * <dd>{@code blockingSubscribe} does not operate by default on a particular {@link Scheduler}.</dd> |
| 2534 | + * <dt><b>Error handling:</b></dt> |
| 2535 | + * <dd>If either {@code onSuccess} or {@code onError} throw, the {@link Throwable} is routed to the |
| 2536 | + * global error handler via {@link RxJavaPlugins#onError(Throwable)}. |
| 2537 | + * If the current thread is interrupted, the {@code onError} consumer is called with an {@link InterruptedException}. |
| 2538 | + * </dd> |
| 2539 | + * </dl> |
| 2540 | + * @param onSuccess the {@link Consumer} to call if the current {@code Maybe} succeeds |
| 2541 | + * @param onError the {@code Consumer} to call if the current {@code Maybe} signals an error |
| 2542 | + * @throws NullPointerException if {@code onSuccess} or {@code onError} is {@code null} |
| 2543 | + * @since 3.0.0 |
| 2544 | + * @see #blockingSubscribe(Consumer, Consumer, Action) |
| 2545 | + */ |
| 2546 | + @SchedulerSupport(SchedulerSupport.NONE) |
| 2547 | + public final void blockingSubscribe(@NonNull Consumer<? super T> onSuccess, @NonNull Consumer<? super Throwable> onError) { |
| 2548 | + blockingSubscribe(onSuccess, onError, Functions.EMPTY_ACTION); |
| 2549 | + } |
| 2550 | + |
| 2551 | + /** |
| 2552 | + * Subscribes to the current {@code Maybe} and calls the appropriate callback on the <em>current thread</em> |
| 2553 | + * when it terminates. |
| 2554 | + * <p> |
| 2555 | + * <img width="640" height="251" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Maybe.blockingSubscribe.cca.png" alt=""> |
| 2556 | + * <dl> |
| 2557 | + * <dt><b>Scheduler:</b></dt> |
| 2558 | + * <dd>{@code blockingSubscribe} does not operate by default on a particular {@link Scheduler}.</dd> |
| 2559 | + * <dt><b>Error handling:</b></dt> |
| 2560 | + * <dd>If either {@code onSuccess}, {@code onError} or {@code onComplete} throw, the {@link Throwable} is routed to the |
| 2561 | + * global error handler via {@link RxJavaPlugins#onError(Throwable)}. |
| 2562 | + * If the current thread is interrupted, the {@code onError} consumer is called with an {@link InterruptedException}. |
| 2563 | + * </dd> |
| 2564 | + * </dl> |
| 2565 | + * @param onSuccess the {@link Consumer} to call if the current {@code Maybe} succeeds |
| 2566 | + * @param onError the {@code Consumer} to call if the current {@code Maybe} signals an error |
| 2567 | + * @param onComplete the {@linnk Action} to call if the current {@code Maybe} completes without a value |
| 2568 | + * @throws NullPointerException if {@code onSuccess}, {@code onError} or {@code onComplete} is {@code null} |
| 2569 | + * @since 3.0.0 |
| 2570 | + */ |
| 2571 | + @SchedulerSupport(SchedulerSupport.NONE) |
| 2572 | + public final void blockingSubscribe(@NonNull Consumer<? super T> onSuccess, @NonNull Consumer<? super Throwable> onError, @NonNull Action onComplete) { |
| 2573 | + Objects.requireNonNull(onSuccess, "onSuccess is null"); |
| 2574 | + Objects.requireNonNull(onError, "onError is null"); |
| 2575 | + Objects.requireNonNull(onComplete, "onComplete is null"); |
| 2576 | + BlockingMultiObserver<T> observer = new BlockingMultiObserver<>(); |
| 2577 | + subscribe(observer); |
| 2578 | + observer.blockingConsume(onSuccess, onError, onComplete); |
| 2579 | + } |
| 2580 | + |
| 2581 | + /** |
| 2582 | + * Subscribes to the current {@code Maybe} and calls the appropriate {@link MaybeObserver} method on the <em>current thread</em>. |
| 2583 | + * <p> |
| 2584 | + * <img width="640" height="398" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Maybe.blockingSubscribe.o.png" alt=""> |
| 2585 | + * <dl> |
| 2586 | + * <dt><b>Scheduler:</b></dt> |
| 2587 | + * <dd>{@code blockingSubscribe} does not operate by default on a particular {@link Scheduler}.</dd> |
| 2588 | + * <dt><b>Error handling:</b></dt> |
| 2589 | + * <dd>An {@code onError} signal is delivered to the {@link MaybeObserver#onError(Throwable)} method. |
| 2590 | + * If any of the {@code MaybeObserver}'s methods throw, the {@link RuntimeException} is propagated to the caller of this method. |
| 2591 | + * If the current thread is interrupted, an {@link InterruptedException} is delivered to {@code observer.onError}. |
| 2592 | + * </dd> |
| 2593 | + * </dl> |
| 2594 | + * @param observer the {@code MaybeObserver} to call methods on the current thread |
| 2595 | + * @throws NullPointerException if {@code observer} is {@code null} |
| 2596 | + * @since 3.0.0 |
| 2597 | + */ |
| 2598 | + @SchedulerSupport(SchedulerSupport.NONE) |
| 2599 | + public final void blockingSubscribe(@NonNull MaybeObserver<? super T> observer) { |
| 2600 | + Objects.requireNonNull(observer, "observer is null"); |
| 2601 | + BlockingDisposableMultiObserver<T> blockingObserver = new BlockingDisposableMultiObserver<>(); |
| 2602 | + observer.onSubscribe(blockingObserver); |
| 2603 | + subscribe(blockingObserver); |
| 2604 | + blockingObserver.blockingConsume(observer); |
| 2605 | + } |
| 2606 | + |
2478 | 2607 | /**
|
2479 | 2608 | * Returns a {@code Maybe} that subscribes to this {@code Maybe} lazily, caches its event
|
2480 | 2609 | * and replays it, to all the downstream subscribers.
|
|
0 commit comments