Package io.atomix.utils.concurrent
Class Futures
java.lang.Object
io.atomix.utils.concurrent.Futures
Utilities for creating completed and exceptional futures.
- Author:
- Jordan Halterman
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <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<Stream<T>>allOf(Stream<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>completedFuture(T result) Creates a future that is synchronously completed.static <T> CompletableFuture<T>Creates a future that is synchronously completed exceptionally.static <T> TGets a future result with a default timeout.static <T> TGets a future result with a default timeout.
-
Constructor Details
-
Futures
public Futures()
-
-
Method Details
-
get
Gets a future result with a default timeout.- Type Parameters:
T- the future result type- Parameters:
future- the future to block- Returns:
- the future result
- Throws:
RuntimeException- if a future exception occurs
-
get
Gets a future result with a default timeout.- Type Parameters:
T- the future result type- Parameters:
future- the future to blocktimeout- the future timeouttimeUnit- the future timeout time unit- Returns:
- the future result
- Throws:
RuntimeException- if a future exception occurs
-
completedFuture
Creates a future that is synchronously completed.- Parameters:
result- The future result.- Returns:
- The completed future.
-
exceptionalFuture
Creates a future that is synchronously completed exceptionally.- Parameters:
t- The future exception.- Returns:
- The exceptionally completed future.
-
allOf
Returns a new CompletableFuture completed with a list of computed values when all of the given CompletableFuture complete.- Type Parameters:
T- value type of CompletableFuture- Parameters:
futures- the CompletableFutures- Returns:
- a new CompletableFuture that is completed when all of the given CompletableFutures complete
-
allOf
Returns a new CompletableFuture completed with a list of computed values when all of the given CompletableFuture complete.- Type Parameters:
T- value type of CompletableFuture- Parameters:
futures- the CompletableFutures- Returns:
- a new CompletableFuture that is completed when all of the given CompletableFutures complete
-
allOf
public 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.- Type Parameters:
T- value type of CompletableFuture- Parameters:
futures- the CompletableFuturesreducer- reducer for computing the resultemptyValue- zero value to be returned if the input future list is empty- Returns:
- a new CompletableFuture that is completed when all of the given CompletableFutures complete
-