/** * Get the current executor associated with the current HTTP context. * * Note that the returned executor is only valid for the current context. It should be used in a transient * fashion, long lived references to it should not be kept. * * @return An executor that will execute its tasks in the current HTTP context. */ public Executor current() { return HttpExecution.fromThread(delegate); } }
/** * Combine the given CompletionStages into a single CompletionStage for the list of results. * * The sequencing operations are performed in the default ExecutionContext. * @param promises The CompletionStages to combine * @param <A> the type of the completion's result. * @return A single CompletionStage whose methods act on the list of redeemed CompletionStage */ @SafeVarargs static <A> CompletionStage<List<A>> sequence(CompletionStage<A>... promises) { return sequence(Arrays.asList(promises)); } }
/** * 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 * Use {@link Futures#sequence(Iterable)} instead. */ public static <A> Promise<List<A>> sequence(Iterable<Promise<A>> promises) { return wrap(Futures.sequence(promises)); }
/** * Create a Promise that is redeemed after a timeout. * * @param message The message to use to redeem the Promise. * @param delay The delay expressed in milliseconds. * Use {@link Futures#timeout(Object, long, TimeUnit)} instead. */ public static <A> Promise<A> timeout(A message, long delay) { return wrap(Futures.timeout(message, delay, TimeUnit.MILLISECONDS)); }
/** * 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. * Use {@link Futures#delayed(Supplier, long, TimeUnit, Executor)} instead. */ public static <A> Promise<A> delayed(Supplier<A> function, long delay, TimeUnit unit, Executor ec) { return wrap(Futures.delayed(function, delay, unit, (ec))); }
public static <A> Promise<A> wrap(CompletionStage<A> future) { return new Promise<>(future); }
/** * Create a Promise that is redeemed after a timeout. * * @param message The message to use to redeem the Promise. * @param delay The delay (expressed with the corresponding unit). * @param unit The Unit. * Use {@link Futures#timeout(Object, long, TimeUnit)} instead. */ public static <A> Promise<A> timeout(A message, long delay, TimeUnit unit) { return (Promise<A>) Futures.timeout(message, delay, unit); }
/** * 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 * @return The promised result * Calling get on a promise is a blocking operation and so introduces the risk of deadlocks * and has serious performance implications. * @throws PromiseTimeoutException when the promise did timeout. */ public A get(long timeout) { return get(timeout, TimeUnit.MILLISECONDS); }
/** * Gets the Scala Future wrapped by this Promise. * * @return The Scala Future * Promise no longer wraps a Scala Future, use asScala instead. */ public Future<A> wrapped() { return asScala(); }
/** * Creates a new Promise with no value */ public static <A> RedeemablePromise<A> empty() { return new RedeemablePromise<>(new CompletableFuture<>()); }
/** * 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 * Use {@link Futures#sequence(CompletionStage[])} instead. */ public static <A> Promise<List<A>> sequence(Promise<A>... promises) { return wrap(Futures.sequence(Arrays.asList(promises))); }
/** * Combine the given CompletionStages into a single CompletionStage for the list of results. * * The sequencing operations are performed in the default ExecutionContext. * @param promises The CompletionStages to combine * @param <A> the type of the completion's result. * @return A single CompletionStage whose methods act on the list of redeemed CompletionStage */ @SafeVarargs static <A> CompletionStage<List<A>> sequence(CompletionStage<A>... promises) { return sequence(Arrays.asList(promises)); } }
/** * Get the current executor associated with the current HTTP context. * * Note that the returned executor is only valid for the current context. It should be used in a transient * fashion, long lived references to it should not be kept. * * @return An executor that will execute its tasks in the current HTTP context. */ public Executor current() { return HttpExecution.fromThread(delegate); } }
/** * Create a Promise timer that throws a PromiseTimeoutException after * a given timeout. * <p> * The returned Promise is usually combined with other Promises. * * @param delay The delay expressed in milliseconds. * Use {@link Futures#timeout(long, TimeUnit)} instead. * @return a promise without a real value */ public static Promise<Void> timeout(long delay) { return wrap(Futures.timeout(delay, TimeUnit.MILLISECONDS)); }
/** * 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. * Use {@link Futures#delayed(Supplier, long, TimeUnit, Executor)} with * {@link Execution#httpPromiseContext()} instead. */ public static <A> Promise<A> delayed(Supplier<A> function, long delay, TimeUnit unit) { return wrap(Futures.delayed(function, delay, unit, Execution.httpPromiseContext())); }
/** * 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>. * Use {@link #thenApplyAsync(Function, Executor)} */ public <B> Promise<B> map(final Function<? super A, ? extends B> function, Executor ec) { return new Promise<>(wrapped.thenApplyAsync(function, (ec))); }
/** * Combine the given CompletionStages into a single CompletionStage for the list of results. * * The sequencing operations are performed in the default ExecutionContext. * @param promises The CompletionStages to combine * @param <A> the type of the completion's result. * @return A single CompletionStage whose methods act on the list of redeemed CompletionStage */ @SafeVarargs static <A> CompletionStage<List<A>> sequence(CompletionStage<A>... promises) { return sequence(Arrays.asList(promises)); } }
/** * Get the current executor associated with the current HTTP context. * * Note that the returned executor is only valid for the current context. It should be used in a transient * fashion, long lived references to it should not be kept. * * @return An executor that will execute its tasks in the current HTTP context. */ public Executor current() { return HttpExecution.fromThread(delegate); } }
/** * Create a Promise timer that throws a PromiseTimeoutException after * a given timeout. * <p> * The returned Promise is usually combined with other Promises. * * @param delay The delay (expressed with the corresponding unit). * @param unit The Unit. * @return a promise without a real value * Use {@link Futures#timeout(long, TimeUnit)} instead. */ public static Promise<Void> timeout(long delay, TimeUnit unit) { return wrap(Futures.timeout(delay, unit)); }
/** * Creates a Promise that wraps a Scala Future. * * @param future The Scala Future to wrap * Use {@link FutureConverters#toJava(Future)} instead. */ public static <A> Promise<A> wrap(Future<A> future) { return new Promise<>(FutureConverters.toJava(future)); }