List<Future> to Future<List> sequence
问题 I am trying to convert List<CompletableFuture<X>> to CompletableFuture<List<T>> . This is quite useful as when you have many asynchronous tasks and you need to get results of all of them. If any of them fails then the final future fails. This is how I have implemented: public static <T> CompletableFuture<List<T>> sequence2(List<CompletableFuture<T>> com, ExecutorService exec) { if(com.isEmpty()){ throw new IllegalArgumentException(); } Stream<? extends CompletableFuture<T>> stream = com