public final class CompletableFutureUtils extends Object
CompletableFuture.| Modifier and Type | Method and Description |
|---|---|
static CompletionException |
errorAsCompletionException(Throwable t)
Wraps the given error in a
CompletionException if necessary. |
static <U> CompletableFuture<U> |
failedFuture(Throwable t)
Convenience method for creating a future that is immediately completed
exceptionally with the given
Throwable. |
static <T> CompletableFuture<T> |
forwardExceptionTo(CompletableFuture<T> src,
CompletableFuture<?> dst)
Forward the
Throwable from src to dst. |
static <T> CompletableFuture<T> |
forwardResultTo(CompletableFuture<T> src,
CompletableFuture<T> dst,
Executor executor)
Completes the
dst future based on the result of the src future asynchronously on
the provided Executor and return the src future. |
static <T> CompletableFuture<T> |
forwardTransformedExceptionTo(CompletableFuture<T> src,
CompletableFuture<?> dst,
Function<Throwable,Throwable> transformationFunction)
Forward the
Throwable that can be transformed as per the transformationFunction
from src to dst. |
static <SourceT,DestT> |
forwardTransformedResultTo(CompletableFuture<SourceT> src,
CompletableFuture<DestT> dst,
Function<SourceT,DestT> function)
Completes the
dst future based on the result of the src future, synchronously,
after applying the provided transformation Function if successful. |
public static <U> CompletableFuture<U> failedFuture(Throwable t)
Throwable.
Similar to CompletableFuture#failedFuture which was added in
Java 9.
U - The type of the element.t - The failure.public static CompletionException errorAsCompletionException(Throwable t)
CompletionException if necessary.
Useful if an exception needs to be rethrown from within CompletableFuture.handle(java.util.function.BiFunction) or similar
methods.t - The error.public static <T> CompletableFuture<T> forwardExceptionTo(CompletableFuture<T> src, CompletableFuture<?> dst)
Throwable from src to dst.src - The source of the Throwable.dst - The destination where the Throwable will be forwarded to.src.public static <T> CompletableFuture<T> forwardTransformedExceptionTo(CompletableFuture<T> src, CompletableFuture<?> dst, Function<Throwable,Throwable> transformationFunction)
Throwable that can be transformed as per the transformationFunction
from src to dst.src - The source of the Throwable.dst - The destination where the Throwable will be forwarded totransformationFunction - Transformation function taht will be applied on to the forwarded exception.public static <T> CompletableFuture<T> forwardResultTo(CompletableFuture<T> src, CompletableFuture<T> dst, Executor executor)
dst future based on the result of the src future asynchronously on
the provided Executor and return the src future.src - The source CompletableFuturedst - The destination where the Throwable or response will be forwarded to.executor - the executor to complete the des futuresrc future.public static <SourceT,DestT> CompletableFuture<SourceT> forwardTransformedResultTo(CompletableFuture<SourceT> src, CompletableFuture<DestT> dst, Function<SourceT,DestT> function)
dst future based on the result of the src future, synchronously,
after applying the provided transformation Function if successful.src - The source CompletableFuturedst - The destination where the Throwable or transformed result will be forwarded to.src future.Copyright © 2022. All rights reserved.