/** * 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. * * @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. * @param ec The ExecutionContext to run the Function0 in. */ public static <A> Promise<A> delayed(Function0<A> function, long delay, TimeUnit unit, ExecutionContext ec) { return FPromiseHelper.delayed(function, delay, unit, ec); }
/** * Creates a new promise which holds the result of this promise if it was completed successfully, * otherwise the result of the {@code fallback} promise if it completed successfully. * If both promises failed, the resulting promise holds the throwable of this promise. * * @param fallback The promise to fallback to if this promise has failed * @return A promise that will delegate to another promise on failure */ public Promise<A> fallbackTo(final Promise<A> fallback) { return FPromiseHelper.fallbackTo(this, fallback); }
/** * Creates a new promise by filtering the value of the current promise with a predicate. * If the predicate fails, the resulting promise will fail with a `NoSuchElementException`. * * @param predicate The predicate to test the current value. * @param ec The ExecutionContext to execute the filtering in. * @return A new promise with the current value, if the predicate is satisfied. */ public Promise<A> filter(final Predicate<? super A> predicate, ExecutionContext ec) { return FPromiseHelper.filter(this, predicate, ec); }
/** * Perform the given <code>action</code> callback if the promise encounters an exception. * * @param action The action to perform. * @param ec The ExecutionContext to execute the callback in. */ public void onFailure(final Callback<Throwable> action, ExecutionContext ec) { FPromiseHelper.onFailure(this, action, ec); }
/** * Maps this promise to a promise of type <code>B</code>. The function <code>function</code> is applied as * soon as the promise is redeemed. * * @param function The function to map <code>A</code> to <code>B</code>. * @param ec The ExecutionContext to execute the function in. * @return A wrapped promise that maps the type from <code>A</code> to <code>B</code>. */ public <B> Promise<B> map(final Function<? super A, B> function, ExecutionContext ec) { return FPromiseHelper.map(this, function, ec); }
/** * Awaits for the promise to get the result.<br> * Throws a Throwable if the calculation providing the promise threw an exception * * @param timeout A user defined timeout in milliseconds * @throws PromiseTimeoutException when the promise did timeout. * @return The promised result */ public A get(long timeout) { return FPromiseHelper.get(this, timeout, TimeUnit.MILLISECONDS); }
/** * 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>. * * @param function The function to map <code>A</code> to a promise for <code>B</code>. * @param ec The ExecutionContext to execute the function in. * @return A wrapped promise for a result of type <code>B</code> */ public <B> Promise<B> flatMap(final Function<? super A,Promise<B>> function, ExecutionContext ec) { return FPromiseHelper.flatMap(this, function, ec); }
private RedeemablePromise(scala.concurrent.Promise<A> promise) { super(FPromiseHelper.getFuture(promise)); this.promise = promise; }
/** * Creates a new Promise with no value */ public static <A> RedeemablePromise<A> empty() { scala.concurrent.Promise<A> p = FPromiseHelper.empty(); return new RedeemablePromise(p); }
/** * Completes this promise with the specified Promise, once that Promise is completed. * * @param other The value to complete with * @param ec An execution context * @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, ExecutionContext ec) { Promise<Void> r = Promise.wrap(FPromiseHelper.completeWith(this.promise, other.future, ec)); return r; }
/** * Perform the given <code>action</code> callback if the promise encounters an exception. * * 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 this promise to a promise of type <code>B</code>. The function <code>function</code> is applied as * soon as the promise is redeemed. * * The function will be run in the default execution context. * * @param function The function to map <code>A</code> to <code>B</code>. * @return A wrapped promise that maps the type from <code>A</code> to <code>B</code>. */ public <B> Promise<B> map(final Function<? super A, B> function) { return FPromiseHelper.map(this, function, HttpExecution.defaultContext()); }
/** * Awaits for the promise to get the result.<br> * Throws a Throwable if the calculation providing the promise threw an exception * * @param timeout A user defined timeout * @param unit timeout for timeout * @throws PromiseTimeoutException when the promise did timeout. * @return The promised result * */ public A get(long timeout, TimeUnit unit) { return FPromiseHelper.get(this, timeout, unit); }
/** * 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>. * * 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()); }
/** * 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. * * 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()); }
/** * Creates a new promise by filtering the value of the current promise with a predicate. * If the predicate fails, the resulting promise will fail with a `NoSuchElementException`. * * @param predicate The predicate to test the current value. * @return A new promise with the current value, if the predicate is satisfied. */ public Promise<A> filter(final Predicate<? super A> predicate) { return FPromiseHelper.filter(this, predicate, HttpExecution.defaultContext()); }