Class FutureUtils

    • Method Detail

      • successfulAsList

        public static <T> CompletableFuture<List<T>> successfulAsList​(List<CompletableFuture<T>> futures)
        Returns a CompletableFuture that completes when all of the given futures complete.

        The resulting list contains the results of each input future, or null for any future that completed exceptionally. This mimics Guava's Futures.successfulAsList behavior.

        Type Parameters:
        T - the result type
        Parameters:
        futures - the list of CompletableFutures to aggregate
        Returns:
        a CompletableFuture containing a list of results (or null for failed futures)
      • allAsList

        public static <T> CompletableFuture<List<T>> allAsList​(Iterable<? extends CompletableFuture<? extends T>> tasks)
        Returns a CompletableFuture that completes when all of the given input futures complete. If all input futures complete successfully, the returned future completes with a list of all results, maintaining the input order.

        If any input future completes exceptionally or is cancelled, the returned future also completes exceptionally. This method is analogous to Guava's Futures.allAsList(tasks).

        Type Parameters:
        T - the result type of the futures
        Parameters:
        tasks - the list of CompletableFutures to combine
        Returns:
        a CompletableFuture that completes with a list of all input results, in order