@Override public CompletableSource apply(Object v) throws Exception { return Completable.wrap(new CompletableSource() { @Override public void subscribe(CompletableObserver observer) { Disposable d1 = Disposables.empty(); observer.onSubscribe(d1); Disposable d2 = Disposables.empty(); observer.onSubscribe(d2); assertFalse(d1.isDisposed()); assertTrue(d2.isDisposed()); } }); } }, new Consumer<Object>() {
/** * Calls the given transformer function with this instance and returns the function's resulting * Completable. * <p> * <img width="640" height="625" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Completable.compose.png" alt=""> * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code compose} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * @param transformer the transformer function, not null * @return the Completable returned by the function * @throws NullPointerException if transformer is null */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Completable compose(CompletableTransformer transformer) { return wrap(ObjectHelper.requireNonNull(transformer, "transformer is null").apply(this)); }
@Test public void wrapCustomCompletable() { Completable.wrap(new CompletableSource() { @Override public void subscribe(CompletableObserver observer) { observer.onSubscribe(Disposables.empty()); observer.onComplete(); } }) .test() .assertResult(); }
/** * Calls the given transformer function with this instance and returns the function's resulting * Completable. * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code compose} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * @param transformer the transformer function, not null * @return the Completable returned by the function * @throws NullPointerException if transformer is null */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Completable compose(CompletableTransformer transformer) { return wrap(ObjectHelper.requireNonNull(transformer, "transformer is null").apply(this)); }
/** * Returns a Completable which completes only when all sources complete, one after another. * <p> * <img width="640" height="283" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Completable.concatArray.png" alt=""> * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code concatArray} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * @param sources the sources to concatenate * @return the Completable instance which completes only when all sources complete * @throws NullPointerException if sources is null */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable concatArray(CompletableSource... sources) { ObjectHelper.requireNonNull(sources, "sources is null"); if (sources.length == 0) { return complete(); } else if (sources.length == 1) { return wrap(sources[0]); } return RxJavaPlugins.onAssembly(new CompletableConcatArray(sources)); }
@Test public void wrapAlreadyCompletable() { assertSame(Completable.complete(), Completable.wrap(Completable.complete())); }
/** * Returns a Completable which terminates as soon as one of the source Completables * terminates (normally or with an error) and disposes all other Completables. * <p> * <img width="640" height="518" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Completable.ambArray.png" alt=""> * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code ambArray} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * @param sources the array of source Completables. A subscription to each source will * occur in the same order as in this array. * @return the new Completable instance * @throws NullPointerException if sources is null */ @CheckReturnValue @NonNull @SchedulerSupport(SchedulerSupport.NONE) public static Completable ambArray(final CompletableSource... sources) { ObjectHelper.requireNonNull(sources, "sources is null"); if (sources.length == 0) { return complete(); } if (sources.length == 1) { return wrap(sources[0]); } return RxJavaPlugins.onAssembly(new CompletableAmb(sources, null)); }
} else if (sources.length == 1) { return wrap(sources[0]);
/** * Returns a Completable which terminates as soon as one of the source Completables * terminates (normally or with an error) and cancels all other Completables. * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code ambArray} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * @param sources the array of source Completables. A subscription to each source will * occur in the same order as in this array. * @return the new Completable instance * @throws NullPointerException if sources is null */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Completable ambArray(final CompletableSource... sources) { ObjectHelper.requireNonNull(sources, "sources is null"); if (sources.length == 0) { return complete(); } if (sources.length == 1) { return wrap(sources[0]); } return RxJavaPlugins.onAssembly(new CompletableAmb(sources, null)); }
/** * Returns a Completable which completes only when all sources complete, one after another. * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code concatArray} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * @param sources the sources to concatenate * @return the Completable instance which completes only when all sources complete * @throws NullPointerException if sources is null */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static Completable concatArray(CompletableSource... sources) { ObjectHelper.requireNonNull(sources, "sources is null"); if (sources.length == 0) { return complete(); } else if (sources.length == 1) { return wrap(sources[0]); } return RxJavaPlugins.onAssembly(new CompletableConcatArray(sources)); }
} else if (sources.length == 1) { return wrap(sources[0]);