Map(Function<? super T, ? extends R> mapper) { this.mapper = requireNonNull(mapper); }
FallbackTo(PromiseImpl<T> chained, Promise<? extends T> fallback) { this.chained = chained; this.fallback = requireNonNull(fallback); }
Filter(Predicate<? super T> predicate) { this.predicate = requireNonNull(predicate); }
Recover(PromiseImpl<T> chained, Function<Promise<?>, ? extends T> recovery) { this.chained = chained; this.recovery = requireNonNull(recovery); }
RecoverWith(PromiseImpl<T> chained, Function<Promise<?>, Promise<? extends T>> recovery) { this.chained = chained; this.recovery = requireNonNull(recovery); }
FlatMap(Function<? super T, Promise<? extends R>> mapper) { this.mapper = requireNonNull(mapper); }
/** * Create a new Promise that has been resolved with the specified failure. * * @param <T> The value type associated with the returned Promise. * @param failure The failure of the resolved Promise. Must not be * {@code null}. * @return A new Promise that has been resolved with the specified failure. */ public static <T> Promise<T> failed(Throwable failure) { return new PromiseImpl<T>(null, requireNonNull(failure)); }
/** * Fail the Promise associated with this Deferred. * * <p> * After the associated Promise is resolved with the specified failure, all * registered {@link Promise#onResolve(Runnable) callbacks} are called and * any {@link Promise#then(Success, Failure) chained} Promises are resolved. * * <p> * Resolving the associated Promise <i>happens-before</i> any registered * callback is called. That is, in a registered callback, * {@link Promise#isDone()} must return {@code true} and * {@link Promise#getValue()} and {@link Promise#getFailure()} must not * block. * * @param failure The failure of the resolved Promise. Must not be * {@code null}. * @throws IllegalStateException If the associated Promise was already * resolved. */ public void fail(Throwable failure) { promise.resolve(null, requireNonNull(failure)); }