public final class Futures extends Object
| Constructor and Description |
|---|
Futures() |
| Modifier and Type | Method and Description |
|---|---|
static <T> CompletableFuture<T> |
asyncFuture(CompletableFuture<T> future,
Executor executor)
Returns a wrapped future that will be completed on the given executor.
|
static <T> CompletableFuture<T> |
blockingAwareFuture(CompletableFuture<T> future,
Executor executor)
Returns a future that's completed using the given
orderedExecutor if the future is not blocked or the
given threadPoolExecutor if the future is blocked. |
static <T> CompletableFuture<T> |
completedFuture(T result)
Creates a future that is synchronously completed.
|
static <T> CompletableFuture<T> |
completedFutureAsync(T result,
Executor executor)
Creates a future that is asynchronously completed.
|
static <T> CompletableFuture<T> |
exceptionalFuture(Throwable t)
Creates a future that is synchronously completed exceptionally.
|
static <T> CompletableFuture<T> |
exceptionalFutureAsync(Throwable t,
Executor executor)
Creates a future that is asynchronously completed exceptionally.
|
static <T> CompletableFuture<T> |
orderedFuture()
Returns a future that completes callbacks in add order.
|
public static <T> CompletableFuture<T> completedFuture(T result)
result - The future result.public static <T> CompletableFuture<T> completedFutureAsync(T result, Executor executor)
result - The future result.executor - The executor on which to complete the future.public static <T> CompletableFuture<T> exceptionalFuture(Throwable t)
t - The future exception.public static <T> CompletableFuture<T> exceptionalFutureAsync(Throwable t, Executor executor)
t - The future exception.executor - The executor on which to complete the future.public static <T> CompletableFuture<T> orderedFuture()
T - future value typepublic static <T> CompletableFuture<T> asyncFuture(CompletableFuture<T> future, Executor executor)
T - the future value typefuture - the future to be completed on the given executorexecutor - the executor with which to complete the futurepublic static <T> CompletableFuture<T> blockingAwareFuture(CompletableFuture<T> future, Executor executor)
orderedExecutor if the future is not blocked or the
given threadPoolExecutor if the future is blocked.
This method allows futures to maintain single-thread semantics via the provided orderedExecutor while
ensuring user code can block without blocking completion of futures. When the returned future or any of its
descendants is blocked on a CompletableFuture.get() or CompletableFuture.join() call, completion
of the returned future will be done using the provided threadPoolExecutor.
T - future value typefuture - the future to convert into an asynchronous futureexecutor - the executor with which to attempt to complete the futureexecutor once the provided
future is completeCopyright © 2013–2017. All rights reserved.