Class AsyncToCompletableFutureAdapter

java.lang.Object
org.jboss.as.protocol.mgmt.AsyncToCompletableFutureAdapter

public final class AsyncToCompletableFutureAdapter extends Object
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 Details

    • AsyncToCompletableFutureAdapter

      public AsyncToCompletableFutureAdapter()
  • Method Details

    • adapt

      public static <T> CompletableFuture<T> adapt(org.jboss.threads.AsyncFuture<T> asyncFuture)
      Adapt the given asyncFuture to complete or cancel a CompletableFuture.
      Type Parameters:
      T - the type provided by the futures
      Parameters:
      asyncFuture - the future that will provide the value. Cannot be null
    • adapt

      public static <T, U> CompletableFuture<U> adapt(org.jboss.threads.AsyncFuture<T> asyncFuture, Function<T,U> transformer, Consumer<Boolean> asyncCancelTask)
      Adapt the given asyncFuture to complete or cancel a CompletableFuture. The given transformer function is applied before completing the CompletableFuture, allowing the CompletableFuture to provide a different type than the AsyncFuture.
      Type Parameters:
      T - the type provided by the asyncFuture
      U - the type to be provided by the @{code CompletableFuture}
      Parameters:
      asyncFuture - the future that will provide the value. Cannot be null
      transformer - a function to convert the type provided by asyncFuture to that provided by the CompletableFuture. Cannot be null
      asyncCancelTask - optional function to perform async cancellation of the ActiveOperation, instead of a call to AsyncFutureTask.asyncCancel(boolean). May be null