@Test public void combineListSuccess(final TestContext testContext) throws Exception { final Async async = testContext.async(); final List<CompletableFuture<Integer>> futureList = Arrays.asList(delayedFuture(2, 100), delayedFuture(3, 300), delayedFuture(1, 200)); FutureUtils.combineFuturesToList(futureList) .thenAccept(l -> { assertThat(l, is(Arrays.asList(2, 3, 1))); async.complete(); }); }
public static <T> CompletableFuture<List<T>> combineFuturesToList(List<CompletableFuture<T>> futureList) { logger.info("combineFuturesToList() called"); return allOf(futureList.stream()) .thenApply(v -> { logger.info("All futures now completed"); return v; }) .thenApply(v -> futureList .stream() .map(f -> f.join()) .collect(toList())); }
FutureUtils { public static <T> CompletableFuture<List<T>> combineFuturesToList(List<CompletableFuture<T>> futureList) { logger.info("combineFuturesToList() called"); return allOf(futureList.stream()) .thenApply(v -> { logger.info("All futures now completed"); return v; }) .thenApply(v -> futureList .stream() .map(f -> f.join()) .collect(toList())); } }
FutureUtils { public static <T> CompletableFuture<List<T>> combineFuturesToList(List<CompletableFuture<T>> futureList) { logger.info("combineFuturesToList() called"); return allOf(futureList.stream()) .thenApply(v -> { logger.info("All futures now completed"); return v; }) .thenApply(v -> futureList .stream() .map(f -> f.join()) .collect(toList())); }  }
FutureUtils { public static <T> CompletableFuture<List<T>> combineFuturesToList(List<CompletableFuture<T>> futureList) { logger.info("combineFuturesToList() called"); return allOf(futureList.stream()) .thenApply(v -> { logger.info("All futures now completed"); return v; }) .thenApply(v -> futureList .stream() .map(f -> f.join()) .collect(toList())); }  static CompletableFuture<Void> allOf(Stream<CompletableFuture<T>> futures); static CompletableFuture<List<T>> combineFuturesToList(List<CompletableFuture<T>> futureList); static CompletableFuture<T> withFallback(final CompletableFuture<T> originalFuture,
                                                                          final Supplier<CompletableFuture<T>> fallbackFutureSupplier); static CompletableFuture<Boolean> allInSequence(final Stream<Supplier<CompletableFuture<Boolean>>> futureSuppliers); static CompletableFuture<Boolean> shortCircuitedFuture(final Stream<Supplier<CompletableFuture<Boolean>>> futureSuppliers,
                                                                  final Boolean fallbackOn); }
FutureUtils { public static <T> CompletableFuture<List<T>> combineFuturesToList(List<CompletableFuture<T>> futureList) { logger.info("combineFuturesToList() called"); return allOf(futureList.stream()) .thenApply(v -> { logger.info("All futures now completed"); return v; }) .thenApply(v -> futureList .stream() .map(f -> f.join()) .collect(toList())); }  static CompletableFuture<Void> allOf(Stream<CompletableFuture<T>> futures); static CompletableFuture<List<T>> combineFuturesToList(List<CompletableFuture<T>> futureList); static CompletableFuture<T> withFallback(final CompletableFuture<T> originalFuture,
                                                                          final Supplier<CompletableFuture<T>> fallbackFutureSupplier); static CompletableFuture<Boolean> allInSequence(final Stream<Supplier<CompletableFuture<Boolean>>> futureSuppliers); static CompletableFuture<Boolean> shortCircuitedFuture(final Stream<Supplier<CompletableFuture<Boolean>>> futureSuppliers,
                                                                  final Boolean fallbackOn);  }