Class FutureUtils


  • public class FutureUtils
    extends java.lang.Object
    Utilities for CompletableFuture.

    Note: When the bitcoinj migration to CompletableFuture is finished this class will either be removed or its remaining methods changed to use generic CompletableFutures.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  FutureUtils.ThrowingSupplier<T>
      Subinterface of Supplier for Lambdas which throw exceptions.
    • Constructor Summary

      Constructors 
      Constructor Description
      FutureUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> java.util.concurrent.CompletableFuture<java.util.List<T>> allAsList​(java.util.List<? extends java.util.concurrent.CompletionStage<? extends T>> stages)
      Note: When the migration to CompletableFuture is complete this routine will either be removed or changed to return a generic CompletableFuture.
      static <T> java.util.concurrent.CompletableFuture<T> failedFuture​(java.lang.Throwable t)
      Can be replaced with CompletableFuture.failedFuture(Throwable) in Java 9+.
      static <T> java.util.concurrent.CompletableFuture<java.util.List<T>> successfulAsList​(java.util.List<? extends java.util.concurrent.CompletionStage<? extends T>> stages)
      Note: When the migration to CompletableFuture is complete this routine will either be removed or changed to return a generic CompletableFuture.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FutureUtils

        public FutureUtils()
    • Method Detail

      • allAsList

        public static <T> java.util.concurrent.CompletableFuture<java.util.List<T>> allAsList​(java.util.List<? extends java.util.concurrent.CompletionStage<? extends T>> stages)
        Note: When the migration to CompletableFuture is complete this routine will either be removed or changed to return a generic CompletableFuture.
        Type Parameters:
        T - the result type
        Parameters:
        stages - A list of CompletionStages all returning the same type
        Returns:
        A CompletableFuture that returns a list of result type
      • successfulAsList

        public static <T> java.util.concurrent.CompletableFuture<java.util.List<T>> successfulAsList​(java.util.List<? extends java.util.concurrent.CompletionStage<? extends T>> stages)
        Note: When the migration to CompletableFuture is complete this routine will either be removed or changed to return a generic CompletableFuture.
        Type Parameters:
        T - the result type
        Parameters:
        stages - A list of CompletionStages all returning the same type
        Returns:
        A CompletableFuture that returns a list of result type
      • failedFuture

        public static <T> java.util.concurrent.CompletableFuture<T> failedFuture​(java.lang.Throwable t)
        Can be replaced with CompletableFuture.failedFuture(Throwable) in Java 9+.
        Type Parameters:
        T - the future's return type
        Parameters:
        t - Exception that is causing the failure
        Returns:
        a failed future containing the specified exception