|
30 | 30 | import io.reactivex.rxjava3.internal.operators.completable.*;
|
31 | 31 | import io.reactivex.rxjava3.internal.operators.flowable.*;
|
32 | 32 | import io.reactivex.rxjava3.internal.operators.maybe.*;
|
33 |
| -import io.reactivex.rxjava3.internal.operators.mixed.SingleFlatMapObservable; |
| 33 | +import io.reactivex.rxjava3.internal.operators.mixed.*; |
34 | 34 | import io.reactivex.rxjava3.internal.operators.observable.*;
|
35 | 35 | import io.reactivex.rxjava3.internal.operators.single.*;
|
36 | 36 | import io.reactivex.rxjava3.internal.util.ErrorMode;
|
@@ -1406,6 +1406,75 @@ public static <T> Single<Boolean> sequenceEqual(@NonNull SingleSource<? extends
|
1406 | 1406 | return RxJavaPlugins.onAssembly(new SingleEquals<>(source1, source2));
|
1407 | 1407 | }
|
1408 | 1408 |
|
| 1409 | + /** |
| 1410 | + * Switches between {@link SingleSource}s emitted by the source {@link Publisher} whenever |
| 1411 | + * a new {@code SingleSource} is emitted, disposing the previously running {@code SingleSource}, |
| 1412 | + * exposing the success items as a {@link Flowable} sequence. |
| 1413 | + * <p> |
| 1414 | + * <img width="640" height="521" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.switchOnNext.png" alt=""> |
| 1415 | + * <dl> |
| 1416 | + * <dt><b>Backpressure:</b></dt> |
| 1417 | + * <dd>The {@code sources} {@code Publisher} is consumed in an unbounded manner (requesting {@link Long#MAX_VALUE}). |
| 1418 | + * The returned {@code Flowable} respects the backpressure from the downstream.</dd> |
| 1419 | + * <dt><b>Scheduler:</b></dt> |
| 1420 | + * <dd>{@code switchOnNext} does not operate by default on a particular {@link Scheduler}.</dd> |
| 1421 | + * <dt><b>Error handling:</b></dt> |
| 1422 | + * <dd>The returned sequence fails with the first error signaled by the {@code sources} {@code Publisher} |
| 1423 | + * or the currently running {@code SingleSource}, disposing the rest. Late errors are |
| 1424 | + * forwarded to the global error handler via {@link RxJavaPlugins#onError(Throwable)}.</dd> |
| 1425 | + * </dl> |
| 1426 | + * @param <T> the element type of the {@code SingleSource}s |
| 1427 | + * @param sources the {@code Publisher} sequence of inner {@code SingleSource}s to switch between |
| 1428 | + * @return the new {@code Flowable} instance |
| 1429 | + * @throws NullPointerException if {@code sources} is {@code null} |
| 1430 | + * @since 3.0.0 |
| 1431 | + * @see #switchOnNextDelayError(Publisher) |
| 1432 | + * @see <a href="http://reactivex.io/documentation/operators/switch.html">ReactiveX operators documentation: Switch</a> |
| 1433 | + */ |
| 1434 | + @BackpressureSupport(BackpressureKind.FULL) |
| 1435 | + @CheckReturnValue |
| 1436 | + @NonNull |
| 1437 | + @SchedulerSupport(SchedulerSupport.NONE) |
| 1438 | + public static <T> Flowable<T> switchOnNext(@NonNull Publisher<@NonNull ? extends SingleSource<? extends T>> sources) { |
| 1439 | + Objects.requireNonNull(sources, "sources is null"); |
| 1440 | + return RxJavaPlugins.onAssembly(new FlowableSwitchMapSinglePublisher<>(sources, Functions.identity(), false)); |
| 1441 | + } |
| 1442 | + |
| 1443 | + /** |
| 1444 | + * Switches between {@link SingleSource}s emitted by the source {@link Publisher} whenever |
| 1445 | + * a new {@code SingleSource} is emitted, disposing the previously running {@code SingleSource}, |
| 1446 | + * exposing the success items as a {@link Flowable} sequence and delaying all errors from |
| 1447 | + * all of them until all terminate. |
| 1448 | + * <p> |
| 1449 | + * <img width="640" height="425" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Maybe.switchOnNextDelayError.png" alt=""> |
| 1450 | + * <dl> |
| 1451 | + * <dt><b>Backpressure:</b></dt> |
| 1452 | + * <dd>The {@code sources} {@code Publisher} is consumed in an unbounded manner (requesting {@link Long#MAX_VALUE}). |
| 1453 | + * The returned {@code Flowable} respects the backpressure from the downstream.</dd> |
| 1454 | + * <dt><b>Scheduler:</b></dt> |
| 1455 | + * <dd>{@code switchOnNextDelayError} does not operate by default on a particular {@link Scheduler}.</dd> |
| 1456 | + * <dt><b>Error handling:</b></dt> |
| 1457 | + * <dd>The returned {@code Flowable} collects all errors emitted by either the {@code sources} |
| 1458 | + * {@code Publisher} or any inner {@code SingleSource} and emits them as a {@link CompositeException} |
| 1459 | + * when all sources terminate. If only one source ever failed, its error is emitted as-is at the end.</dd> |
| 1460 | + * </dl> |
| 1461 | + * @param <T> the element type of the {@code SingleSource}s |
| 1462 | + * @param sources the {@code Publisher} sequence of inner {@code SingleSource}s to switch between |
| 1463 | + * @return the new {@code Flowable} instance |
| 1464 | + * @throws NullPointerException if {@code sources} is {@code null} |
| 1465 | + * @since 3.0.0 |
| 1466 | + * @see #switchOnNext(Publisher) |
| 1467 | + * @see <a href="http://reactivex.io/documentation/operators/switch.html">ReactiveX operators documentation: Switch</a> |
| 1468 | + */ |
| 1469 | + @BackpressureSupport(BackpressureKind.FULL) |
| 1470 | + @CheckReturnValue |
| 1471 | + @NonNull |
| 1472 | + @SchedulerSupport(SchedulerSupport.NONE) |
| 1473 | + public static <T> Flowable<T> switchOnNextDelayError(@NonNull Publisher<@NonNull ? extends SingleSource<? extends T>> sources) { |
| 1474 | + Objects.requireNonNull(sources, "sources is null"); |
| 1475 | + return RxJavaPlugins.onAssembly(new FlowableSwitchMapSinglePublisher<>(sources, Functions.identity(), true)); |
| 1476 | + } |
| 1477 | + |
1409 | 1478 | /**
|
1410 | 1479 | * <strong>Advanced use only:</strong> creates a {@code Single} instance without
|
1411 | 1480 | * any safeguards by using a callback that is called with a {@link SingleObserver}.
|
@@ -3758,6 +3827,7 @@ public final Single<T> retry(@NonNull Predicate<? super Throwable> predicate) {
|
3758 | 3827 | * @param stop the function that should return {@code true} to stop retrying
|
3759 | 3828 | * @return the new {@code Single} instance
|
3760 | 3829 | * @throws NullPointerException if {@code stop} is {@code null}
|
| 3830 | + * @since 3.0.0 |
3761 | 3831 | */
|
3762 | 3832 | @CheckReturnValue
|
3763 | 3833 | @NonNull
|
|
0 commit comments