/** * Signals a TimeoutException if the Perhaps doesn't signal an item * within the specified time. * @param timeout the time to wait for an item * @param unit the unit of time * @return the new Perhaps instance */ public final Perhaps<T> timeout(long timeout, TimeUnit unit) { return timeout(timeout, unit, Schedulers.computation()); }
/** * 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 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, Perhaps<? extends T> fallback) { return timeout(timeout, unit, Schedulers.computation(), fallback); }
/** * 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)); }
/** * 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 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)); }
/** * 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 TimeoutException if the Perhaps doesn't signal an item * within the specified time. * @param timeout the time to wait for an item * @param unit the unit of time * @return the new Perhaps instance */ public final Perhaps<T> timeout(long timeout, TimeUnit unit) { return timeout(timeout, unit, Schedulers.computation()); }
/** * 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 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, Perhaps<? extends T> fallback) { return timeout(timeout, unit, Schedulers.computation(), fallback); }
@Test public void timeoutError() { Perhaps.error(new IOException()).timeout(1, TimeUnit.MINUTES) .test() .assertFailure(IOException.class); }
@Test public void timeoutNormal() { Perhaps.just(1).timeout(1, TimeUnit.MINUTES) .test() .assertResult(1); }