public class CompletableFuturesExtra extends Object
| Modifier and Type | Class and Description |
|---|---|
private static class |
CompletableFuturesExtra.Identity |
private static class |
CompletableFuturesExtra.WrapFunction |
| Modifier | Constructor and Description |
|---|---|
private |
CompletableFuturesExtra() |
| Modifier and Type | Method and Description |
|---|---|
static <T> void |
checkCompleted(CompletionStage<T> stage)
check that a stage is completed.
|
static <T> CompletionStage<T> |
dereference(CompletionStage<? extends CompletionStage<T>> stage)
This takes a stage of a stage of a value and
returns a plain stage of a value.
|
static <T> CompletableFuture<T> |
exceptionallyCompletedFuture(Throwable throwable)
Returns a new CompletableFuture that is already exceptionally completed with
the given exception.
|
static <T> CompletionStage<T> |
exceptionallyCompose(CompletionStage<T> stage,
java.util.function.Function<Throwable,? extends CompletionStage<T>> fn)
Returns a new stage that, when this stage completes
exceptionally, is executed with this stage's exception as the
argument to the supplied function.
|
static <T> T |
getCompleted(CompletionStage<T> stage)
Get the value of a completed stage.
|
static <T,U> CompletionStage<U> |
handleCompose(CompletionStage<T> stage,
java.util.function.BiFunction<? super T,Throwable,? extends CompletionStage<U>> fn)
Returns a new stage that, when this stage completes
either normally or exceptionally, is executed with this stage's
result and exception as arguments to the supplied function.
|
static <V> CompletableFuture<V> |
toCompletableFuture(com.google.common.util.concurrent.ListenableFuture<V> future)
Wrap a
ListenableFuture in a CompletableFuture. |
static <V> com.google.common.util.concurrent.ListenableFuture<V> |
toListenableFuture(CompletableFuture<V> future)
Wrap a
CompletableFuture in a ListenableFuture. |
static <V> com.google.common.util.concurrent.ListenableFuture<V> |
toListenableFuture(CompletionStage<V> future)
Wrap a
CompletionStage in a ListenableFuture. |
private static <T> CompletionStage<CompletionStage<T>> |
wrap(CompletionStage<T> future) |
public static <V> CompletableFuture<V> toCompletableFuture(com.google.common.util.concurrent.ListenableFuture<V> future)
ListenableFuture in a CompletableFuture. The returned future will
complete with the same result or failure as the original future. Completing the returned
future does not complete the original future.future - The ListenableFuture to wrap in a CompletableFuture.CompletableFuture that completes when the original future completes.public static <V> com.google.common.util.concurrent.ListenableFuture<V> toListenableFuture(CompletableFuture<V> future)
CompletableFuture in a ListenableFuture. The returned future will
complete with the same result or failure as the original future.future - The CompletableFuture to wrap in a ListenableFuture.ListenableFuture that completes when the original future completes.public static <V> com.google.common.util.concurrent.ListenableFuture<V> toListenableFuture(CompletionStage<V> future)
CompletionStage in a ListenableFuture. The returned future will
complete with the same result or failure as the original future.future - The CompletionStage to wrap in a ListenableFuture.ListenableFuture that completes when the original future completes.public static <T> CompletableFuture<T> exceptionallyCompletedFuture(Throwable throwable)
throwable - the exceptionpublic static <T,U> CompletionStage<U> handleCompose(CompletionStage<T> stage, java.util.function.BiFunction<? super T,Throwable,? extends CompletionStage<U>> fn)
When this stage is complete, the given function is invoked
with the result (or null if none) and the exception (or
null if none) of this stage as arguments, and the
function's result is used to complete the returned stage.
This differs from
CompletionStage.handle(java.util.function.BiFunction)
in that the function should return a CompletionStage rather than
the value directly.
U - the function's return typestage - the CompletionStage to composefn - the function to use to compute the value of the
returned CompletionStageCompletionStagepublic static <T> CompletionStage<T> exceptionallyCompose(CompletionStage<T> stage, java.util.function.Function<Throwable,? extends CompletionStage<T>> fn)
CompletionStage.exceptionally(java.util.function.Function)
in that the function should return a CompletionStage rather than
the value directly.stage - the CompletionStage to composefn - the function to use to compute the value of the
returned CompletionStage if this stage completed
exceptionallyCompletionStagepublic static <T> void checkCompleted(CompletionStage<T> stage)
stage - a CompletionStage.IllegalStateException - if the stage is not completed.public static <T> T getCompleted(CompletionStage<T> stage)
stage - a completed CompletionStage.IllegalStateException - if the stage is not completed.com.google.common.util.concurrent.UncheckedExecutionException - if the future has failed with a non-runtime exception, otherwise
the actual exceptionpublic static <T> CompletionStage<T> dereference(CompletionStage<? extends CompletionStage<T>> stage)
stage - a CompletionStage of a CompletionStage of a valueCompletionStage of the valueprivate static <T> CompletionStage<CompletionStage<T>> wrap(CompletionStage<T> future)
Copyright © 2015 Spotify AB. All Rights Reserved.