Class CompletableFutureHelper

java.lang.Object
org.eclipse.microprofile.fault.tolerance.tck.asynchronous.CompletableFutureHelper

public class CompletableFutureHelper extends Object
Author:
Ondrej Mihalyi
  • Method Details

    • failedFuture

      public static <U> CompletableFuture<U> failedFuture(Throwable ex)
      Creates a future completed with a supplied exception. Equivalent to CompletableFuture.failedFuture available since Java 9 but not in Java 8.
      Type Parameters:
      U - The type of the future result
      Parameters:
      ex - The exception to finish the result with
      Returns:
      A future completed with the a supplied exception ex
    • toCompletableFuture

      public static <U> CompletableFuture<U> toCompletableFuture(CompletionStage<U> stage)
      Returns a future that is completed when the stage is completed and has the same value or exception as the completed stage. It's supposed to be equivalent to calling CompletionStage.toCompletableFuture() but works with any CompletionStage and doesn't throw UnsupportedOperationException.
      Type Parameters:
      U - The type of the future result
      Parameters:
      stage - Stage to convert to a future
      Returns:
      Future converted from stage