Package org.eclipse.microprofile.fault.tolerance.tck.asynchronous

# Class CompletableFutureHelper

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

public class CompletableFutureHelper extends Object

Author:
  Ondrej Mihalyi

## Method Summary

Modifier and Type
Method
Description
`static <U> CompletableFuture<U>`
`failedFuture(Throwable ex)`
Creates a future completed with a supplied exception.
`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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## 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