Package org.jboss.as.protocol.mgmt
Class AsyncToCompletableFutureAdapter
java.lang.Object
org.jboss.as.protocol.mgmt.AsyncToCompletableFutureAdapter
Utility that adapts an
AsyncFuture to a CompletableFuture
by using an AsyncFuture.Listener to complete or cancel the CompletableFuture
and by ensuring calls to CompletableFuture.cancel(boolean) result in appropriate
cancellation of the AsyncFuture.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> CompletableFuture<T>adapt(org.jboss.threads.AsyncFuture<T> asyncFuture) Adapt the givenasyncFutureto complete or cancel aCompletableFuture.static <T,U> CompletableFuture<U> adapt(org.jboss.threads.AsyncFuture<T> asyncFuture, Function<T, U> transformer, Consumer<Boolean> asyncCancelTask) Adapt the givenasyncFutureto complete or cancel aCompletableFuture.
-
Constructor Details
-
AsyncToCompletableFutureAdapter
public AsyncToCompletableFutureAdapter()
-
-
Method Details
-
adapt
Adapt the givenasyncFutureto complete or cancel aCompletableFuture.- Type Parameters:
T- the type provided by the futures- Parameters:
asyncFuture- the future that will provide the value. Cannot benull
-
adapt
public static <T,U> CompletableFuture<U> adapt(org.jboss.threads.AsyncFuture<T> asyncFuture, Function<T, U> transformer, Consumer<Boolean> asyncCancelTask) Adapt the givenasyncFutureto complete or cancel aCompletableFuture. The giventransformerfunction is applied beforecompletingtheCompletableFuture, allowing theCompletableFutureto provide a different type than theAsyncFuture.- Type Parameters:
T- the type provided by theasyncFutureU- the type to be provided by the @{code CompletableFuture}- Parameters:
asyncFuture- the future that will provide the value. Cannot benulltransformer- a function to convert the type provided byasyncFutureto that provided by theCompletableFuture. Cannot benullasyncCancelTask- optional function to perform async cancellation of the ActiveOperation, instead of a call toAsyncFutureTask.asyncCancel(boolean). May benull
-