public class MoreFutures
extends java.lang.Object
Standards for these utilities:
CompletionStage
as a future value.
CompletableFuture
only to the producer of a future value.
Modifier and Type | Class and Description |
---|---|
static class |
MoreFutures.ExceptionOrResult<T>
An object that represents either a result or an exceptional termination.
|
Constructor and Description |
---|
MoreFutures() |
Modifier and Type | Method and Description |
---|---|
static <T> java.util.concurrent.CompletionStage<java.util.List<T>> |
allAsList(java.util.Collection<? extends java.util.concurrent.CompletionStage<? extends T>> futures)
Like
CompletableFuture.allOf(java.util.concurrent.CompletableFuture<?>...) but returning the result of constituent futures. |
static <T> java.util.concurrent.CompletionStage<java.util.List<MoreFutures.ExceptionOrResult<T>>> |
allAsListWithExceptions(java.util.Collection<? extends java.util.concurrent.CompletionStage<? extends T>> futures)
Like
allAsList(java.util.Collection<? extends java.util.concurrent.CompletionStage<? extends T>>) but return a list . |
static <T> T |
get(java.util.concurrent.CompletionStage<T> future)
Gets the result of the given future.
|
static <T> T |
get(java.util.concurrent.CompletionStage<T> future,
long duration,
java.util.concurrent.TimeUnit unit)
Gets the result of the given future.
|
static boolean |
isCancelled(java.util.concurrent.CompletionStage<?> future)
Indicates whether the future is cancelled.
|
static boolean |
isDone(java.util.concurrent.CompletionStage<?> future)
Indicates whether the future is done.
|
static java.util.concurrent.CompletionStage<java.lang.Void> |
runAsync(ThrowingRunnable runnable)
Shorthand for
runAsync(ThrowingRunnable, ExecutorService) using ForkJoinPool.commonPool() . |
static java.util.concurrent.CompletionStage<java.lang.Void> |
runAsync(ThrowingRunnable runnable,
java.util.concurrent.ExecutorService executorService)
Like
CompletableFuture.runAsync(java.lang.Runnable) but for ThrowingRunnable . |
static <T> java.util.concurrent.CompletionStage<T> |
supplyAsync(ThrowingSupplier<T> supplier)
Shorthand for
supplyAsync(ThrowingSupplier, ExecutorService) using ForkJoinPool.commonPool() . |
static <T> java.util.concurrent.CompletionStage<T> |
supplyAsync(ThrowingSupplier<T> supplier,
java.util.concurrent.ExecutorService executorService)
Like
CompletableFuture.supplyAsync(Supplier) but for ThrowingSupplier . |
public static <T> T get(java.util.concurrent.CompletionStage<T> future) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
This utility is provided so consumers of futures need not even convert to CompletableFuture
, an interface that is only suitable for producers of futures.
java.lang.InterruptedException
java.util.concurrent.ExecutionException
public static <T> T get(java.util.concurrent.CompletionStage<T> future, long duration, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
This utility is provided so consumers of futures need not even convert to CompletableFuture
, an interface that is only suitable for producers of futures.
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
public static boolean isDone(java.util.concurrent.CompletionStage<?> future)
This utility is provided so consumers of futures need not even convert to CompletableFuture
, an interface that is only suitable for producers of futures.
public static boolean isCancelled(java.util.concurrent.CompletionStage<?> future)
This utility is provided so consumers of futures need not even convert to CompletableFuture
, an interface that is only suitable for producers of futures.
public static <T> java.util.concurrent.CompletionStage<T> supplyAsync(ThrowingSupplier<T> supplier, java.util.concurrent.ExecutorService executorService)
CompletableFuture.supplyAsync(Supplier)
but for ThrowingSupplier
.
If the ThrowingSupplier
throws an exception, the future completes exceptionally.
public static <T> java.util.concurrent.CompletionStage<T> supplyAsync(ThrowingSupplier<T> supplier)
supplyAsync(ThrowingSupplier, ExecutorService)
using ForkJoinPool.commonPool()
.public static java.util.concurrent.CompletionStage<java.lang.Void> runAsync(ThrowingRunnable runnable, java.util.concurrent.ExecutorService executorService)
CompletableFuture.runAsync(java.lang.Runnable)
but for ThrowingRunnable
.
If the ThrowingRunnable
throws an exception, the future completes exceptionally.
public static java.util.concurrent.CompletionStage<java.lang.Void> runAsync(ThrowingRunnable runnable)
runAsync(ThrowingRunnable, ExecutorService)
using ForkJoinPool.commonPool()
.public static <T> java.util.concurrent.CompletionStage<java.util.List<T>> allAsList(java.util.Collection<? extends java.util.concurrent.CompletionStage<? extends T>> futures)
CompletableFuture.allOf(java.util.concurrent.CompletableFuture<?>...)
but returning the result of constituent futures.public static <T> java.util.concurrent.CompletionStage<java.util.List<MoreFutures.ExceptionOrResult<T>>> allAsListWithExceptions(java.util.Collection<? extends java.util.concurrent.CompletionStage<? extends T>> futures)
allAsList(java.util.Collection<? extends java.util.concurrent.CompletionStage<? extends T>>)
but return a list .