/** * Returns a Single that emits the item emitted by the source Single until a Completable terminates. Upon * termination of {@code other}, this will emit a {@link CancellationException} rather than go to * {@link SingleObserver#onSuccess(Object)}. * <p> * <img width="640" height="380" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/takeUntil.png" alt=""> * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code takeUntil} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * * @param other * the Completable whose termination will cause {@code takeUntil} to emit the item from the source * Single * @return a Single that emits the item emitted by the source Single until such time as {@code other} terminates. * @see <a href="http://reactivex.io/documentation/operators/takeuntil.html">ReactiveX operators documentation: TakeUntil</a> */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single<T> takeUntil(final CompletableSource other) { ObjectHelper.requireNonNull(other, "other is null"); return takeUntil(new CompletableToObservable<T>(other)); }
/** * Returns a Single that emits the item emitted by the source Single until a second Single emits an item. Upon * emission of an item from {@code other}, this will emit a {@link CancellationException} rather than go to * {@link SingleObserver#onSuccess(Object)}. * <p> * <img width="640" height="380" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/takeUntil.png" alt=""> * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code takeUntil} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * * @param other * the Single whose emitted item will cause {@code takeUntil} to emit the item from the source Single * @param <E> * the type of item emitted by {@code other} * @return a Single that emits the item emitted by the source Single until such time as {@code other} emits its item * @see <a href="http://reactivex.io/documentation/operators/takeuntil.html">ReactiveX operators documentation: TakeUntil</a> */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final <E> Single<T> takeUntil(final SingleSource<? extends E> other) { ObjectHelper.requireNonNull(other, "other is null"); return takeUntil(new SingleToObservable<E>(other)); }
/** * Returns a Single that emits the item emitted by the source Single until a Completable terminates. Upon * termination of {@code other}, this will emit a {@link CancellationException} rather than go to * {@link SingleObserver#onSuccess(Object)}. * <p> * <img width="640" height="380" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/takeUntil.png" alt=""> * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code takeUntil} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * * @param other * the Completable whose termination will cause {@code takeUntil} to emit the item from the source * Single * @return a Single that emits the item emitted by the source Single until such time as {@code other} terminates. * @see <a href="http://reactivex.io/documentation/operators/takeuntil.html">ReactiveX operators documentation: TakeUntil</a> */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Single<T> takeUntil(final CompletableSource other) { ObjectHelper.requireNonNull(other, "other is null"); return takeUntil(new CompletableToObservable<T>(other)); }
/** * Returns a Single that emits the item emitted by the source Single until a second Single emits an item. Upon * emission of an item from {@code other}, this will emit a {@link CancellationException} rather than go to * {@link SingleObserver#onSuccess(Object)}. * <p> * <img width="640" height="380" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/takeUntil.png" alt=""> * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code takeUntil} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * * @param other * the Single whose emitted item will cause {@code takeUntil} to emit the item from the source Single * @param <E> * the type of item emitted by {@code other} * @return a Single that emits the item emitted by the source Single until such time as {@code other} emits its item * @see <a href="http://reactivex.io/documentation/operators/takeuntil.html">ReactiveX operators documentation: TakeUntil</a> */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final <E> Single<T> takeUntil(final SingleSource<? extends E> other) { ObjectHelper.requireNonNull(other, "other is null"); return takeUntil(new SingleToObservable<E>(other)); }
@Test public void withPublisherDispose() { TestHelper.checkDisposed(Single.never().takeUntil(Observable.never())); }
@Test public void otherSignalsAndCompletes() { List<Throwable> errors = TestCommonHelper.trackPluginErrors(); try { Single.just(1).takeUntil(Observable.just(1).take(1)) .test() .assertFailure(CancellationException.class); assertTrue(errors.toString(), errors.isEmpty()); } finally { RxJavaCommonPlugins.reset(); } } }
@Test public void otherOnNextPublisher() { PublishSubject<Integer> pp = PublishSubject.create(); PublishSubject<Integer> source = PublishSubject.create(); TestObserver<Integer> ts = source.single(-99).takeUntil(pp) .test(); pp.onNext(1); ts.assertFailure(CancellationException.class); }
@Test public void otherOnCompletePublisher() { PublishSubject<Integer> pp = PublishSubject.create(); PublishSubject<Integer> source = PublishSubject.create(); TestObserver<Integer> ts = source.single(-99).takeUntil(pp) .test(); pp.onComplete(); ts.assertFailure(CancellationException.class); }
@Test public void otherErrorPublisher() { PublishSubject<Integer> pp = PublishSubject.create(); PublishSubject<Integer> source = PublishSubject.create(); TestObserver<Integer> ts = source.single(-99).takeUntil(pp) .test(); pp.onError(new TestException()); ts.assertFailure(TestException.class); }
@Test public void mainSuccessPublisher() { PublishSubject<Integer> pp = PublishSubject.create(); PublishSubject<Integer> source = PublishSubject.create(); TestObserver<Integer> ts = source.single(-99).takeUntil(pp) .test(); source.onNext(1); source.onComplete(); ts.assertResult(1); }
@Test public void mainErrorPublisher() { PublishSubject<Integer> pp = PublishSubject.create(); PublishSubject<Integer> source = PublishSubject.create(); TestObserver<Integer> ts = source.single(-99).takeUntil(pp) .test(); source.onError(new TestException()); ts.assertFailure(TestException.class); }
@Test public void otherOnCompleteCompletable() { PublishSubject<Integer> pp = PublishSubject.create(); PublishSubject<Integer> source = PublishSubject.create(); TestObserver<Integer> ts = source.single(-99).takeUntil(pp.ignoreElements()) .test(); pp.onComplete(); ts.assertFailure(CancellationException.class); }
@Test public void otherErrorSingle() { PublishSubject<Integer> pp = PublishSubject.create(); PublishSubject<Integer> source = PublishSubject.create(); TestObserver<Integer> ts = source.single(-99).takeUntil(pp.single(-99)) .test(); pp.onError(new TestException()); ts.assertFailure(TestException.class); }
@Test public void mainSuccessCompletable() { PublishSubject<Integer> pp = PublishSubject.create(); PublishSubject<Integer> source = PublishSubject.create(); TestObserver<Integer> ts = source.single(-99).takeUntil(pp.ignoreElements()) .test(); source.onNext(1); source.onComplete(); ts.assertResult(1); }
@Test public void otherOnNextCompletable() { PublishSubject<Integer> pp = PublishSubject.create(); PublishSubject<Integer> source = PublishSubject.create(); TestObserver<Integer> ts = source.single(-99).takeUntil(pp.ignoreElements()) .test(); pp.onNext(1); pp.onComplete(); ts.assertFailure(CancellationException.class); }
@Test public void mainSuccessSingle() { PublishSubject<Integer> pp = PublishSubject.create(); PublishSubject<Integer> source = PublishSubject.create(); TestObserver<Integer> ts = source.single(-99).takeUntil(pp.single(-99)) .test(); source.onNext(1); source.onComplete(); ts.assertResult(1); }
@Test public void mainErrorSingle() { PublishSubject<Integer> pp = PublishSubject.create(); PublishSubject<Integer> source = PublishSubject.create(); TestObserver<Integer> ts = source.single(-99).takeUntil(pp.single(-99)) .test(); source.onError(new TestException()); ts.assertFailure(TestException.class); }
@Test public void mainErrorCompletable() { PublishSubject<Integer> pp = PublishSubject.create(); PublishSubject<Integer> source = PublishSubject.create(); TestObserver<Integer> ts = source.single(-99).takeUntil(pp.ignoreElements()) .test(); source.onError(new TestException()); ts.assertFailure(TestException.class); }
@Test public void otherOnNextSingle() { PublishSubject<Integer> pp = PublishSubject.create(); PublishSubject<Integer> source = PublishSubject.create(); TestObserver<Integer> ts = source.single(-99).takeUntil(pp.single(-99)) .test(); pp.onNext(1); pp.onComplete(); ts.assertFailure(CancellationException.class); }
@Test public void otherErrorCompletable() { PublishSubject<Integer> pp = PublishSubject.create(); PublishSubject<Integer> source = PublishSubject.create(); TestObserver<Integer> ts = source.single(-99).takeUntil(pp.ignoreElements()) .test(); pp.onError(new TestException()); ts.assertFailure(TestException.class); }