public final class Futures extends Object
| Constructor and Description |
|---|
Futures() |
| Modifier and Type | Method and Description |
|---|---|
static <T> CompletableFuture<List<T>> |
allOf(List<CompletableFuture<T>> futures)
Returns a new CompletableFuture completed with a list of computed values
when all of the given CompletableFuture complete.
|
static <T> CompletableFuture<T> |
allOf(List<CompletableFuture<T>> futures,
BinaryOperator<T> reducer,
T emptyValue)
Returns a new CompletableFuture completed by reducing a list of computed values
when all of the given CompletableFuture complete.
|
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> |
firstOf(List<CompletableFuture<T>> futures,
Match<T> positiveResultMatcher,
T negativeResult)
Returns a new CompletableFuture completed by with the first positive result from a list of
input CompletableFutures.
|
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 completepublic static <T> CompletableFuture<List<T>> allOf(List<CompletableFuture<T>> futures)
T - value type of CompletableFuturefutures - the CompletableFuturespublic static <T> CompletableFuture<T> allOf(List<CompletableFuture<T>> futures, BinaryOperator<T> reducer, T emptyValue)
T - value type of CompletableFuturefutures - the CompletableFuturesreducer - reducer for computing the resultemptyValue - zero value to be returned if the input future list is emptypublic static <T> CompletableFuture<T> firstOf(List<CompletableFuture<T>> futures, Match<T> positiveResultMatcher, T negativeResult)
T - value type of CompletableFuturefutures - the input list of CompletableFuturespositiveResultMatcher - matcher to identify a positive resultnegativeResult - value to complete with if none of the futures complete with a positive resultCopyright © 2013–2018. All rights reserved.