Java 8 CompletableFuture.allOf(…) with Collection or List

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

  1. 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

  2. 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.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment