public class Futures
extends java.lang.Object
CompletionStage.| Constructor and Description |
|---|
Futures() |
| Modifier and Type | Method and Description |
|---|---|
static <A> java.util.concurrent.CompletionStage<A> |
delayed(java.util.function.Supplier<A> supplier,
long delay,
java.util.concurrent.TimeUnit unit,
java.util.concurrent.Executor executor)
Create a CompletionStage which, after a delay, will be redeemed with the result of a
given supplier.
|
static <A> java.util.concurrent.CompletionStage<java.util.List<A>> |
sequence(java.util.concurrent.CompletionStage<A>... promises)
Combine the given CompletionStages into a single CompletionStage for the list of results.
|
static <A> java.util.concurrent.CompletionStage<java.util.List<A>> |
sequence(java.lang.Iterable<? extends java.util.concurrent.CompletionStage<A>> promises)
Combine the given CompletionStages into a single CompletionStage for the list of results.
|
static <A> java.util.concurrent.CompletionStage<A> |
timeout(A value,
long delay,
java.util.concurrent.TimeUnit unit)
Create a CompletionStage that is redeemed after a timeout.
|
static <A> java.util.concurrent.CompletionStage<A> |
timeout(long delay,
java.util.concurrent.TimeUnit unit)
Creates a CompletionStage timer that throws a PromiseTimeoutException after
a given timeout.
|
public static <A> java.util.concurrent.CompletionStage<java.util.List<A>> sequence(java.lang.Iterable<? extends java.util.concurrent.CompletionStage<A>> promises)
A - the type of the completion's result.promises - The CompletionStages to combinepublic static <A> java.util.concurrent.CompletionStage<java.util.List<A>> sequence(java.util.concurrent.CompletionStage<A>... promises)
A - the type of the completion's result.promises - The CompletionStages to combinepublic static <A> java.util.concurrent.CompletionStage<A> timeout(A value,
long delay,
java.util.concurrent.TimeUnit unit)
A - the type of the completion's result.value - The result value to use to complete the CompletionStage.delay - The delay (expressed with the corresponding unit).unit - The time unit, i.e. java.util.concurrent.TimeUnit.MILLISECONDSpublic static <A> java.util.concurrent.CompletionStage<A> timeout(long delay,
java.util.concurrent.TimeUnit unit)
completionStage.applyToEither(timeout, Function.identity())
The underlying implementation uses TimerTask, which has a
resolution in milliseconds.
A previous implementation used CompletionStage<Void> which made
it unsuitable for composition. Cast with Futures.<Void>timeout if
necessary.A - the type of the completion's result.delay - The delay (expressed with the corresponding unit).unit - The time Unit.public static <A> java.util.concurrent.CompletionStage<A> delayed(java.util.function.Supplier<A> supplier,
long delay,
java.util.concurrent.TimeUnit unit,
java.util.concurrent.Executor executor)
A - the type of the completion's result.supplier - The supplier to call to fulfill the CompletionStage.delay - The time to wait.unit - The units to use for the delay.executor - The executor to run the supplier in.