/** * Delay the subscription to this Perhaps by the given time amount. * @param delay the amount to delay the subscription * @param unit the delay time unit * @return the new Perhaps instance */ public final Perhaps<T> delaySubscription(long delay, TimeUnit unit) { return delaySubscription(timer(delay, unit)); }
/** * 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)); }
/** * Switch to the fallback Perhaps if this Perhaps doesn't signal an * item (or terminates) within the specified time. * @param timeout the time to wait for an item * @param unit the unit of time * @param scheduler the scheduler to wait on * @param fallback the Perhaps to switch to if this Perhaps times out * @return the new Perhaps instance */ public final Perhaps<T> timeout(long timeout, TimeUnit unit, Scheduler scheduler, Perhaps<? extends T> fallback) { return timeout(timer(timeout, unit, scheduler), fallback); }
/** * Delay the subscription to this Perhaps by the given time amount, * running on the specified Scheduler. * @param delay the amount to delay the subscription * @param unit the delay time unit * @param scheduler the scheduler to wait on * @return the new Perhaps instance */ public final Perhaps<T> delaySubscription(long delay, TimeUnit unit, Scheduler scheduler) { return delaySubscription(timer(delay, unit, scheduler)); }
/** * Signals a TimeoutException if the Perhaps doesn't signal an item * or (terminates) within the specified time. * @param timeout the time to wait for an item * @param unit the unit of time * @param scheduler the scheduler to wait on * @return the new Perhaps instance */ public final Perhaps<T> timeout(long timeout, TimeUnit unit, Scheduler scheduler) { return timeout(timer(timeout, unit, scheduler)); }
/** * Delay the subscription to this Perhaps by the given time amount, * running on the specified Scheduler. * @param delay the amount to delay the subscription * @param unit the delay time unit * @param scheduler the scheduler to wait on * @return the new Perhaps instance */ public final Perhaps<T> delaySubscription(long delay, TimeUnit unit, Scheduler scheduler) { return delaySubscription(timer(delay, unit, scheduler)); }
/** * Switch to the fallback Perhaps if this Perhaps doesn't signal an * item (or terminates) within the specified time. * @param timeout the time to wait for an item * @param unit the unit of time * @param scheduler the scheduler to wait on * @param fallback the Perhaps to switch to if this Perhaps times out * @return the new Perhaps instance */ public final Perhaps<T> timeout(long timeout, TimeUnit unit, Scheduler scheduler, Perhaps<? extends T> fallback) { return timeout(timer(timeout, unit, scheduler), fallback); }
/** * Signals a 0L after the specified amount of time has passed since * subscription. * @param delay the delay time * @param unit the time unit * @return the new Perhaps instance */ public static Perhaps<Long> timer(long delay, TimeUnit unit) { return timer(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)); }
/** * Signals a 0L after the specified amount of time has passed since * subscription. * @param delay the delay time * @param unit the time unit * @return the new Perhaps instance */ public static Perhaps<Long> timer(long delay, TimeUnit unit) { return timer(delay, unit, Schedulers.computation()); }
/** * Signals a TimeoutException if the Perhaps doesn't signal an item * or (terminates) within the specified time. * @param timeout the time to wait for an item * @param unit the unit of time * @param scheduler the scheduler to wait on * @return the new Perhaps instance */ public final Perhaps<T> timeout(long timeout, TimeUnit unit, Scheduler scheduler) { return timeout(timer(timeout, unit, scheduler)); }
/** * Delay the subscription to this Perhaps by the given time amount. * @param delay the amount to delay the subscription * @param unit the delay time unit * @return the new Perhaps instance */ public final Perhaps<T> delaySubscription(long delay, TimeUnit unit) { return delaySubscription(timer(delay, unit)); }
@Test public void timer() { Perhaps.timer(100, TimeUnit.MILLISECONDS) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(0L); }
@Test public void timerScheduler() { Perhaps.timer(100, TimeUnit.MILLISECONDS, Schedulers.single()) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(0L); }