/** * Combine the given promises into a single promise for the list of results. * * <p>The sequencing operations are performed in the default ExecutionContext. * * @param promises The promises to combine * @return A single promise whose methods act on the list of redeemed promises */ public static <A> Promise<List<A>> sequence(Promise<? extends A>... promises) { return FPromiseHelper.<A>sequence( java.util.Arrays.asList(promises), HttpExecution.defaultContext()); }
/** * Completes this promise with the specified Promise, once that Promise is completed. * * @param other The value to complete with * @return A promise giving the result of attempting to complete this promise with the other * promise. If the completion was successful then the result will be a null value, if the * completion failed then the result will be an IllegalStateException. */ public Promise<Void> completeWith(Promise other) { return this.completeWith(other, HttpExecution.defaultContext()); }
/** * Completes this promise with the specified Promise, once that Promise is completed. * * @param other The value to complete with * @return A promise giving the result of attempting to complete this promise with the other * promise. If the completion was successful then the result will be true, if the completion * couldn't occur then the result will be false. */ public Promise<Boolean> tryCompleteWith(Promise other) { return this.tryCompleteWith(other, HttpExecution.defaultContext()); }
/** * Perform the given <code>action</code> callback if the promise encounters an exception. * * <p>This action will be run in the default exceution context. * * @param action The action to perform. */ public void onFailure(final Callback<Throwable> action) { FPromiseHelper.onFailure(this, action, HttpExecution.defaultContext()); }
/** * Maps the result of this promise to a promise for a result of type <code>B</code>, and * flattens that to be a single promise for <code>B</code>. * * <p>The function will be run in the default execution context. * * @param function The function to map <code>A</code> to a promise for <code>B</code>. * @return A wrapped promise for a result of type <code>B</code> */ public <B> Promise<B> flatMap(final Function<? super A, Promise<B>> function) { return FPromiseHelper.flatMap(this, function, HttpExecution.defaultContext()); }
/** * Wraps this promise in a promise that will handle exceptions thrown by this Promise. * * <p>The function will be run in the default execution context. * * @param function The function to handle the exception. This may, for example, convert the * exception into something of type <code>T</code>, or it may throw another exception, or it * may do some other handling. * @return A wrapped promise that will only throw an exception if the supplied <code>function * </code> throws an exception. */ public Promise<A> recover(final Function<Throwable, A> function) { return FPromiseHelper.recover(this, function, HttpExecution.defaultContext()); }
/** * Perform the given <code>action</code> callback when the Promise is redeemed. * * <p>The callback will be run in the default execution context. * * @param action The action to perform. */ public void onRedeem(final Callback<A> action) { FPromiseHelper.onRedeem(this, action, HttpExecution.defaultContext()); }
/** * Create a Promise which, after a delay, will be redeemed with the result of a given function. * The function will be called after the delay. * * <p>The function will be run in the default ExecutionContext. * * @param function The function to call to fulfill the Promise. * @param delay The time to wait. * @param unit The units to use for the delay. */ public static <A> Promise<A> delayed(Function0<A> function, long delay, TimeUnit unit) { return FPromiseHelper.delayed(function, delay, unit, HttpExecution.defaultContext()); }
/** * Create a Promise which will be redeemed with the result of a given function. * * <p>The Function0 will be run in the default ExecutionContext. * * @param function Used to fulfill the Promise. */ public static <A> Promise<A> promise(Function0<A> function) { return FPromiseHelper.promise(function, HttpExecution.defaultContext()); }
/** * Combine the given promises into a single promise for the list of results. * * <p>The sequencing operations are performed in the default ExecutionContext. * * @param promises The promises to combine * @return A single promise whose methods act on the list of redeemed promises */ public static <A> Promise<List<A>> sequence(Iterable<Promise<? extends A>> promises) { return FPromiseHelper.<A>sequence(promises, HttpExecution.defaultContext()); }