/** * Delays the actual subscription to the current Single until the given time delay elapsed. * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code delaySubscription} does by default subscribe to the current Single * on the {@code computation} {@link Scheduler} after the delay.</dd> * </dl> * @param <U> the element type of the other source * @param time the time amount to wait with the subscription * @param unit the time unit of the waiting * @return the new Single instance * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final <U> Single<T> delaySubscription(long time, TimeUnit unit) { return delaySubscription(time, unit, Schedulers.computation()); }
/** * Delays the actual subscription to the current Single until the given time delay elapsed. * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code delaySubscription} does by default subscribe to the current Single * on the {@code computation} {@link Scheduler} after the delay.</dd> * </dl> * @param <U> the element type of the other source * @param time the time amount to wait with the subscription * @param unit the time unit of the waiting * @return the new Single instance * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.COMPUTATION) public final <U> Single<T> delaySubscription(long time, TimeUnit unit) { return delaySubscription(time, unit, Schedulers.computation()); }
/** * Delays the actual subscription to the current Single until the given time delay elapsed. * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code delaySubscription} does by default subscribe to the current Single * on the {@link Scheduler} you provided, after the delay.</dd> * </dl> * @param <U> the element type of the other source * @param time the time amount to wait with the subscription * @param unit the time unit of the waiting * @param scheduler the scheduler to wait on and subscribe on to the current Single * @return the new Single instance * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final <U> Single<T> delaySubscription(long time, TimeUnit unit, Scheduler scheduler) { return delaySubscription(Observable.timer(time, unit, scheduler)); }
/** * Delays the actual subscription to the current Single until the given time delay elapsed. * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code delaySubscription} does by default subscribe to the current Single * on the {@link Scheduler} you provided, after the delay.</dd> * </dl> * @param <U> the element type of the other source * @param time the time amount to wait with the subscription * @param unit the time unit of the waiting * @param scheduler the scheduler to wait on and subscribe on to the current Single * @return the new Single instance * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final <U> Single<T> delaySubscription(long time, TimeUnit unit, Scheduler scheduler) { return delaySubscription(Observable.timer(time, unit, scheduler)); }
@Test public void withSingleDispose() { TestHelper.checkDisposed(Single.just(1).delaySubscription(Single.just(2))); }
@Test public void delaySubscriptionTime() throws Exception { Single.just(1).delaySubscription(100, TimeUnit.MILLISECONDS) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }
@Test public void withPublisherDispose() { TestHelper.checkDisposed(PublishSubject.create().singleOrError().delaySubscription(Observable.just(1))); }
@Test public void withObservableDispose() { TestHelper.checkDisposed(PublishSubject.create().singleOrError().delaySubscription(Observable.just(1))); }
@Test public void delaySubscriptionSingle() throws Exception { Single.just(1).delaySubscription(Single.timer(100, TimeUnit.MILLISECONDS)) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }
@Test public void delaySubscriptionTimeCustomScheduler() throws Exception { Single.just(1).delaySubscription(100, TimeUnit.MILLISECONDS, Schedulers.io()) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }
@Test public void delaySubscriptionObservable() throws Exception { Single.just(1).delaySubscription(Observable.timer(100, TimeUnit.MILLISECONDS)) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }
@Test public void withPublisherError() { Single.just(1) .delaySubscription(Observable.error(new TestException())) .test() .assertFailure(TestException.class); }
@Test public void withObservableError() { Single.just(1) .delaySubscription(Observable.error(new TestException())) .test() .assertFailure(TestException.class); }
@Test public void withSingleErrors() { Single.just(1) .delaySubscription(Single.error(new TestException())) .test() .assertFailure(TestException.class); }
@Test public void delaySubscriptionCompletable() throws Exception { Single.just(1).delaySubscription(Completable.complete().delay(100, TimeUnit.MILLISECONDS)) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }
@Test public void withPublisherError2() { List<Throwable> errors = TestCommonHelper.trackPluginErrors(); try { Single.just(1) .delaySubscription(new Observable<Integer>() { @Override protected void subscribeActual(Observer<? super Integer> s) { s.onSubscribe(Disposables.empty()); s.onNext(1); s.onError(new TestException()); } }) .test() .assertResult(1); TestCommonHelper.assertUndeliverable(errors, 0, TestException.class); } finally { RxJavaCommonPlugins.reset(); } }
@Test public void withObservableError2() { List<Throwable> errors = TestCommonHelper.trackPluginErrors(); try { Single.just(1) .delaySubscription(new Observable<Integer>() { @Override protected void subscribeActual(Observer<? super Integer> s) { s.onSubscribe(Disposables.empty()); s.onNext(1); s.onError(new TestException()); } }) .test() .assertResult(1); TestCommonHelper.assertUndeliverable(errors, 0, TestException.class); } finally { RxJavaCommonPlugins.reset(); } }