@Override public Object apply(Observable<Integer> o) throws Exception { return o.flatMapCompletable(new Function<Integer, CompletableSource>() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.complete(); } }); } }, false, 1, null);
/** * Maps each element of the upstream Observable into CompletableSources, subscribes to them and * waits until the upstream and all CompletableSources complete. * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code flatMapCompletable} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * @param mapper the function that received each source value and transforms them into CompletableSources. * @return the new Completable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Completable flatMapCompletable(Function<? super T, ? extends CompletableSource> mapper) { return flatMapCompletable(mapper, false); }
/** * Maps each element of the upstream Observable into CompletableSources, subscribes to them and * waits until the upstream and all CompletableSources complete. * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code flatMapCompletable} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * @param mapper the function that received each source value and transforms them into CompletableSources. * @return the new Completable instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Completable flatMapCompletable(Function<? super T, ? extends CompletableSource> mapper) { return flatMapCompletable(mapper, false); }
@Override public Object apply(Observable<Integer> o) throws Exception { return o.flatMapCompletable(new Function<Integer, CompletableSource>() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.complete(); } }).toObservable(); } }, false, 1, null);
@Test public void disposed() { TestHelper.checkDisposed(Observable.range(1, 10) .flatMapCompletable(new Function<Integer, CompletableSource>() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.complete(); } })); }
@Test public void normalDelayError() { Observable.range(1, 10) .flatMapCompletable(new Function<Integer, CompletableSource>() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.complete(); } }, true) .test() .assertResult(); }
@Test public void normal() { Observable.range(1, 10) .flatMapCompletable(new Function<Integer, CompletableSource>() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.complete(); } }) .test() .assertResult(); }
@Test public void disposedObservable() { TestHelper.checkDisposed(Observable.range(1, 10) .flatMapCompletable(new Function<Integer, CompletableSource>() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.complete(); } }).toObservable()); }
@Test public void normalObservable() { Observable.range(1, 10) .flatMapCompletable(new Function<Integer, CompletableSource>() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.complete(); } }).toObservable() .test() .assertResult(); }
@Test public void normalDelayErrorObservable() { Observable.range(1, 10) .flatMapCompletable(new Function<Integer, CompletableSource>() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.complete(); } }, true).toObservable() .test() .assertResult(); }
@Test public void normalAsync() { Observable.range(1, 1000) .flatMapCompletable(new Function<Integer, CompletableSource>() { @Override public CompletableSource apply(Integer v) throws Exception { return Observable.range(1, 100).subscribeOn(Schedulers.computation()).ignoreElements(); } }) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(); }
@Test public void normalDelayInnerErrorAll() { TestObserver<Void> to = Observable.range(1, 10) .flatMapCompletable(new Function<Integer, CompletableSource>() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.error(new TestException()); } }, true) .test() .assertFailure(CompositeException.class); List<Throwable> errors = TestCommonHelper.compositeList(to.errors().get(0)); for (int i = 0; i < 10; i++) { TestCommonHelper.assertError(errors, i, TestException.class); } }
@Test public void normalAsyncObservable() { Observable.range(1, 1000) .flatMapCompletable(new Function<Integer, CompletableSource>() { @Override public CompletableSource apply(Integer v) throws Exception { return Observable.range(1, 100).subscribeOn(Schedulers.computation()).ignoreElements(); } }).toObservable() .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(); }
@Test public void normalDelayInnerErrorAllObservable() { TestObserver<Integer> to = Observable.range(1, 10) .flatMapCompletable(new Function<Integer, CompletableSource>() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.error(new TestException()); } }, true).<Integer>toObservable() .test() .assertFailure(CompositeException.class); List<Throwable> errors = TestCommonHelper.compositeList(to.errors().get(0)); for (int i = 0; i < 10; i++) { TestCommonHelper.assertError(errors, i, TestException.class); } }
@Test public void normalNonDelayErrorOuter() { Observable.range(1, 10).concatWith(Observable.<Integer>error(new TestException())) .flatMapCompletable(new Function<Integer, CompletableSource>() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.complete(); } }, false) .test() .assertFailure(TestException.class); }
@Test public void normalNonDelayErrorOuterObservable() { Observable.range(1, 10).concatWith(Observable.<Integer>error(new TestException())) .flatMapCompletable(new Function<Integer, CompletableSource>() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.complete(); } }, false).toObservable() .test() .assertFailure(TestException.class); }
@Test public void normalDelayErrorAll() { TestObserver<Void> to = Observable.range(1, 10).concatWith(Observable.<Integer>error(new TestException())) .flatMapCompletable(new Function<Integer, CompletableSource>() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.error(new TestException()); } }, true) .test() .assertFailure(CompositeException.class); List<Throwable> errors = TestCommonHelper.compositeList(to.errors().get(0)); for (int i = 0; i < 11; i++) { TestCommonHelper.assertError(errors, i, TestException.class); } }
@Test public void normalDelayErrorAllObservable() { TestObserver<Integer> to = Observable.range(1, 10).concatWith(Observable.<Integer>error(new TestException())) .flatMapCompletable(new Function<Integer, CompletableSource>() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.error(new TestException()); } }, true).<Integer>toObservable() .test() .assertFailure(CompositeException.class); List<Throwable> errors = TestCommonHelper.compositeList(to.errors().get(0)); for (int i = 0; i < 11; i++) { TestCommonHelper.assertError(errors, i, TestException.class); } }
@Test public void fusedObservable() { TestObserver<Integer> to = ObserverFusion.newTest(QueueDisposable.ANY); Observable.range(1, 10) .flatMapCompletable(new Function<Integer, CompletableSource>() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.complete(); } }).<Integer>toObservable() .subscribe(to); to .assertOf(ObserverFusion.<Integer>assertFuseable()) .assertOf(ObserverFusion.<Integer>assertFusionMode(QueueDisposable.ASYNC)) .assertResult(); }
@Test public void fused() { TestObserver<Integer> to = ObserverFusion.newTest(QueueDisposable.ANY); Observable.range(1, 10) .flatMapCompletable(new Function<Integer, CompletableSource>() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.complete(); } }) .<Integer>toObservable() .subscribe(to); to .assertOf(ObserverFusion.<Integer>assertFuseable()) .assertOf(ObserverFusion.<Integer>assertFusionMode(QueueDisposable.ASYNC)) .assertResult(); }