/** * Delay the emission of the signals of this Perhaps by the * given amount of time. * @param delay the delay amount * @param unit the time unit of the delay * @param scheduler the scheduler to delay on * @return the new Perhaps instance */ public final Perhaps<T> delay(long delay, TimeUnit unit, Scheduler scheduler) { return delay(timer(delay, unit, scheduler)); }
/** * Delay the emission of the signals of this Perhaps by the * given amount of time. * @param delay the delay amount * @param unit the time unit of the delay * @return the new Perhaps instance */ public final Perhaps<T> delay(long delay, TimeUnit unit) { return delay(delay, unit, Schedulers.computation()); }
/** * Delay the emission of the signals of this Perhaps by the * given amount of time. * @param delay the delay amount * @param unit the time unit of the delay * @param scheduler the scheduler to delay on * @return the new Perhaps instance */ public final Perhaps<T> delay(long delay, TimeUnit unit, Scheduler scheduler) { return delay(timer(delay, unit, scheduler)); }
/** * Delay the emission of the signals of this Perhaps by the * given amount of time. * @param delay the delay amount * @param unit the time unit of the delay * @return the new Perhaps instance */ public final Perhaps<T> delay(long delay, TimeUnit unit) { return delay(delay, unit, Schedulers.computation()); }
@Test public void delayError() { Perhaps.error(new IOException()).delay(100, TimeUnit.MILLISECONDS) .test() .awaitDone(5, TimeUnit.SECONDS) .assertFailure(IOException.class); }
@Test public void delay() { Perhaps.just(1).delay(100, TimeUnit.MILLISECONDS) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }
@Test public void delayScheduler() { Perhaps.just(1).delay(100, TimeUnit.MILLISECONDS, Schedulers.single()) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }
@Test public void delayPublisherError2() { PublishProcessor<Integer> pp = PublishProcessor.create(); TestSubscriber<Integer> ts = Perhaps.<Integer>error(new IOException()) .delay(pp).test(); ts.assertEmpty(); assertTrue(pp.hasSubscribers()); pp.onError(new IllegalArgumentException()); ts.assertFailure(CompositeException.class); assertFalse(pp.hasSubscribers()); }
@Test public void delayPublisherError() { PublishProcessor<Integer> pp = PublishProcessor.create(); TestSubscriber<Integer> ts = Perhaps.<Integer>error(new IOException()) .delay(pp).test(); ts.assertEmpty(); assertTrue(pp.hasSubscribers()); pp.onNext(2); ts.assertFailure(IOException.class); assertFalse(pp.hasSubscribers()); }
@Test public void delayPublisher() { PublishProcessor<Integer> pp = PublishProcessor.create(); TestSubscriber<Integer> ts = Perhaps.just(1).delay(pp).test(); ts.assertEmpty(); assertTrue(pp.hasSubscribers()); pp.onNext(2); ts.assertResult(1); assertFalse(pp.hasSubscribers()); }