Functional { public static <R> Future<List<R>> allOfFutures(List<Future<R>> futures) { return CompositeFutureImpl.all(futures.toArray(new Future[futures.size()])) .map(v -> futures.stream() .map(Future::result) .collect(Collectors.toList()) ); } private  Functional(); static Future<List<R>> allOfFutures(List<Future<R>> futures);  }
@Test public void testSequenceFuture() throws Exception { List<Future<Integer>> list1 = Arrays.asList(Future.succeededFuture(2), Future.succeededFuture(9), Future.succeededFuture(17)); Future<List<Integer>> fs1 = Functional.allOfFutures(list1); List<Integer> cpList = Arrays.asList(2, 9, 17); assertEquals(fs1.succeeded(), true); assertEquals(fs1.result(), cpList); List<Future<Integer>> list2 = Arrays.asList(Future.succeededFuture(2), Future.failedFuture("Oops"), Future.succeededFuture(17)); Future<List<Integer>> fs2 = Functional.allOfFutures(list2); assertEquals(fs2.succeeded(), false); assertEquals(fs2.cause().getMessage(), "Oops"); }