|
17 | 17 | import java.util.concurrent.*;
|
18 | 18 | import java.util.stream.*;
|
19 | 19 |
|
20 |
| -import org.reactivestreams.Publisher; |
| 20 | +import org.reactivestreams.*; |
21 | 21 |
|
22 | 22 | import io.reactivex.rxjava3.annotations.*;
|
23 | 23 | import io.reactivex.rxjava3.disposables.Disposable;
|
@@ -1323,6 +1323,81 @@ public static <T> Flowable<T> merge(
|
1323 | 1323 | return merge(Flowable.fromArray(source1, source2, source3, source4));
|
1324 | 1324 | }
|
1325 | 1325 |
|
| 1326 | + /** |
| 1327 | + * Merges an array of {@link SingleSource} instances into a single {@link Flowable} sequence, |
| 1328 | + * running all {@code SingleSource}s at once. |
| 1329 | + * <p> |
| 1330 | + * <img width="640" height="272" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.mergeArray.png" alt=""> |
| 1331 | + * <dl> |
| 1332 | + * <dt><b>Backpressure:</b></dt> |
| 1333 | + * <dd>The operator honors backpressure from downstream.</dd> |
| 1334 | + * <dt><b>Scheduler:</b></dt> |
| 1335 | + * <dd>{@code mergeArray} does not operate by default on a particular {@link Scheduler}.</dd> |
| 1336 | + * <dt><b>Error handling:</b></dt> |
| 1337 | + * <dd>If any of the source {@code SingleSource}s signal a {@link Throwable} via {@code onError}, the resulting |
| 1338 | + * {@code Flowable} terminates with that {@code Throwable} and all other source {@code SingleSource}s are disposed. |
| 1339 | + * If more than one {@code SingleSource} signals an error, the resulting {@code Flowable} may terminate with the |
| 1340 | + * first one's error or, depending on the concurrency of the sources, may terminate with a |
| 1341 | + * {@link CompositeException} containing two or more of the various error signals. |
| 1342 | + * {@code Throwable}s that didn't make into the composite will be sent (individually) to the global error handler via |
| 1343 | + * {@link RxJavaPlugins#onError(Throwable)} method as {@link UndeliverableException} errors. Similarly, {@code Throwable}s |
| 1344 | + * signaled by source(s) after the returned {@code Flowable} has been cancelled or terminated with a |
| 1345 | + * (composite) error will be sent to the same global error handler. |
| 1346 | + * Use {@link #mergeArrayDelayError(SingleSource...)} to merge sources and terminate only when all source {@code SingleSource}s |
| 1347 | + * have completed or failed with an error. |
| 1348 | + * </dd> |
| 1349 | + * </dl> |
| 1350 | + * @param <T> the common and resulting value type |
| 1351 | + * @param sources the array sequence of {@code SingleSource} sources |
| 1352 | + * @return the new {@code Flowable} instance |
| 1353 | + * @throws NullPointerException if {@code sources} is {@code null} |
| 1354 | + * @see #mergeArrayDelayError(SingleSource...) |
| 1355 | + */ |
| 1356 | + @BackpressureSupport(BackpressureKind.FULL) |
| 1357 | + @CheckReturnValue |
| 1358 | + @NonNull |
| 1359 | + @SchedulerSupport(SchedulerSupport.NONE) |
| 1360 | + @SafeVarargs |
| 1361 | + public static <T> Flowable<T> mergeArray(SingleSource<? extends T>... sources) { |
| 1362 | + return Flowable.fromArray(sources).flatMapSingle(Functions.identity(), false, sources.length); |
| 1363 | + } |
| 1364 | + |
| 1365 | + /** |
| 1366 | + * Flattens an array of {@link SingleSource}s into one {@link Flowable}, in a way that allows a subscriber to receive all |
| 1367 | + * successfully emitted items from each of the source {@code SingleSource}s without being interrupted by an error |
| 1368 | + * notification from one of them. |
| 1369 | + * <p> |
| 1370 | + * <img width="640" height="422" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.mergeArrayDelayError.png" alt=""> |
| 1371 | + * <p> |
| 1372 | + * This behaves like {@link #merge(Publisher)} except that if any of the merged {@code SingleSource}s notify of an |
| 1373 | + * error via {@link Subscriber#onError onError}, {@code mergeArrayDelayError} will refrain from propagating that |
| 1374 | + * error notification until all of the merged {@code SingleSource}s have finished emitting items. |
| 1375 | + * <p> |
| 1376 | + * Even if multiple merged {@code SingleSource}s send {@code onError} notifications, {@code mergeArrayDelayError} will only |
| 1377 | + * invoke the {@code onError} method of its subscribers once. |
| 1378 | + * <dl> |
| 1379 | + * <dt><b>Backpressure:</b></dt> |
| 1380 | + * <dd>The operator honors backpressure from downstream.</dd> |
| 1381 | + * <dt><b>Scheduler:</b></dt> |
| 1382 | + * <dd>{@code mergeArrayDelayError} does not operate by default on a particular {@link Scheduler}.</dd> |
| 1383 | + * </dl> |
| 1384 | + * |
| 1385 | + * @param <T> the common element base type |
| 1386 | + * @param sources |
| 1387 | + * the array of {@code SingleSource}s |
| 1388 | + * @return the new {@code Flowable} instance |
| 1389 | + * @throws NullPointerException if {@code sources} is {@code null} |
| 1390 | + * @see <a href="http://reactivex.io/documentation/operators/merge.html">ReactiveX operators documentation: Merge</a> |
| 1391 | + */ |
| 1392 | + @BackpressureSupport(BackpressureKind.FULL) |
| 1393 | + @CheckReturnValue |
| 1394 | + @SchedulerSupport(SchedulerSupport.NONE) |
| 1395 | + @SafeVarargs |
| 1396 | + @NonNull |
| 1397 | + public static <T> Flowable<T> mergeArrayDelayError(@NonNull SingleSource<? extends T>... sources) { |
| 1398 | + return Flowable.fromArray(sources).flatMapSingle(Functions.identity(), true, sources.length); |
| 1399 | + } |
| 1400 | + |
1326 | 1401 | /**
|
1327 | 1402 | * Merges an {@link Iterable} sequence of {@link SingleSource} instances into one {@link Flowable} sequence,
|
1328 | 1403 | * running all {@code SingleSource}s at once and delaying any error(s) until all sources succeed or fail.
|
|
0 commit comments