Class CompletableFutures


  • public final class CompletableFutures
    extends Object
    • Method Detail

      • allAsList

        public static <T> CompletableFuture<List<T>> allAsList​(List<CompletableFuture<T>> futures)
        Returns a CompletableFuture which will complete after all futures have completed, and when complete, will contain the value of all futures.

        If any of the futures fail, the resulting CompletableFuture will complete exceptionally with that future's failure.

        Type Parameters:
        T - paramter
        Parameters:
        futures - a list of futures
        Returns:
        completableFuture of list
      • failedFuture

        public static <T> CompletableFuture<T> failedFuture​(Throwable exception)
        Returns a CompletableFuture that is completed exceptionally with the given exception.
        Type Parameters:
        T - parameter
        Parameters:
        exception - Throwable
        Returns:
        completableFuture
      • catchingCompose

        public static <T,​E extends ThrowableCompletableFuture<T> catchingCompose​(CompletableFuture<T> future,
                                                                                         Class<E> exceptionClass,
                                                                                         Function<? super E,​? extends CompletableFuture<T>> handler)
        Returns a new CompletableFuture that is completed when future is complete, catching the given exceptionClass.

        If future completes normally, then the returned future completes normally with the same value. If future completes exceptionally with an exceptionClass, the returned future completes with the result of the handler. Otherwise, the returned future will complete exceptionally with the same exception as future.

        Type Parameters:
        T - parameter
        E - parameter
        Parameters:
        future - the completable future
        exceptionClass - exception class
        handler - the function handler
        Returns:
        T