public final class Futures extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> BiConsumer<T,Throwable> |
copyHandler(CompletableFuture<T> copyFuture)
Creates a future handler that will copy the state of the handled future
to the given future.
|
static <T> CompletableFuture<T> |
create(Supplier<CompletableFuture<T>> initiator)
Create a
CompletableFuture using the given supplier. |
static <T> BiConsumer<T,Throwable> |
handler(BiConsumer<T,Throwable> delegate)
Creates a future handler that will delegate to the given
BiConsumer
after having unwrapped the throwable passed as input if it is a CompletionException. |
static <T,R> BiFunction<T,Throwable,R> |
handler(BiFunction<T,Throwable,R> delegate)
Creates a future handler that will delegate to the given
BiFunction
after having unwrapped the throwable passed as input if it is a CompletionException. |
static <T> Function<Throwable,T> |
handler(Function<Throwable,T> delegate)
Creates a future handler that will delegate to the given
Function
after having unwrapped the throwable passed as input if it is a CompletionException. |
static <T,R> Function<T,CompletionStage<R>> |
safeComposer(Function<? super T,? extends CompletionStage<R>> delegate)
Creates a composition function that will delegate to the given
Function
but will catch any exception during composition to return a future completed exceptionally. |
static <T> CompletableFuture<T> |
whenCompleteExecute(CompletableFuture<?> self,
Supplier<? extends CompletionStage<T>> action)
Compose the given future with another as soon as it's complete,
regardless of errors, and return a completable future that
will take errors of both parent futures into account
(using
Throwable.addSuppressed(Throwable) if need be). |
public static <T> CompletableFuture<T> create(Supplier<CompletableFuture<T>> initiator)
CompletableFuture using the given supplier.
This method is guaranteed to never throw any exception: any exception thrown by
the given supplier will instead complete the resulting future
exceptionally.
This is useful in particular if you want to handle errors during the CompletableFuture
creation the same way as errors thrown during post-processing operations
(for instance operations passed to CompletableFuture.thenApply(Function)).
initiator - A supplier that will initiate (synchronously) the asynchronous operation.CompletableFuture wrapping the result of both the initiation and execution of the operation.public static <T> Function<Throwable,T> handler(Function<Throwable,T> delegate)
Function
after having unwrapped the throwable passed as input if it is a CompletionException.
This method is meant to be used in conjunction with CompletableFuture.exceptionally(Function).
delegate - The exception function to delegate topublic static <T,R> BiFunction<T,Throwable,R> handler(BiFunction<T,Throwable,R> delegate)
BiFunction
after having unwrapped the throwable passed as input if it is a CompletionException.
This method is meant to be used in conjunction with CompletableFuture.handle(BiFunction).
delegate - The handler to delegate topublic static <T> BiConsumer<T,Throwable> handler(BiConsumer<T,Throwable> delegate)
BiConsumer
after having unwrapped the throwable passed as input if it is a CompletionException.
This method is meant to be used in conjunction with CompletableFuture.whenComplete(BiConsumer).
delegate - The handler to delegate topublic static <T> BiConsumer<T,Throwable> copyHandler(CompletableFuture<T> copyFuture)
This method is meant to be used in conjunction with CompletableFuture.whenComplete(BiConsumer).
copyFuture - The future to copy topublic static <T,R> Function<T,CompletionStage<R>> safeComposer(Function<? super T,? extends CompletionStage<R>> delegate)
Function
but will catch any exception during composition to return a future completed exceptionally.
This method is meant to be used in conjunction with CompletableFuture.thenCompose(Function).
It is useful in particular when you want to apply the same error handling to the composition
function and to the resulting future.
delegate - The composition function to delegate to.public static <T> CompletableFuture<T> whenCompleteExecute(CompletableFuture<?> self, Supplier<? extends CompletionStage<T>> action)
Throwable.addSuppressed(Throwable) if need be).self - The future to wait for before launching the next oneaction - the composition consumerself finished executing and
action and its resulting future finished executing.Copyright © 2006–2017 Hibernate. All rights reserved.