We Are Going To Discuss About Java 8 CompletableFuture.allOf(…) with Collection or List . So lets Start this Java Article.
Java 8 CompletableFuture.allOf(…) with Collection or List
- Java 8 CompletableFuture.allOf(…) with Collection or List
Unfortunately, to my knowledge CompletableFuture does not support collections.
You could do something like this to make the code a bit cleaner, but it essentially does the same thing - Java 8 CompletableFuture.allOf(…) with Collection or List
Unfortunately, to my knowledge CompletableFuture does not support collections.
You could do something like this to make the code a bit cleaner, but it essentially does the same thing
Solution 1
Unfortunately, to my knowledge CompletableFuture does not support collections.
You could do something like this to make the code a bit cleaner, but it essentially does the same thing
public <T> CompletableFuture<List<T>> allOf(List<CompletableFuture<T>> futuresList) {
CompletableFuture<Void> allFuturesResult =
CompletableFuture.allOf(futuresList.toArray(new CompletableFuture[futuresList.size()]));
return allFuturesResult.thenApply(v ->
futuresList.stream().
map(future -> future.join()).
collect(Collectors.<T>toList())
);
}
Found this very informative : http://www.nurkiewicz.com/2013/05/java-8-completablefuture-in-action.html
Original Author Deepak Of This Content
Conclusion
So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.