Created
May 17, 2017 10:04
-
-
Save milanboers/85c164b6d35f70f7c39b6d5e3b6864b6 to your computer and use it in GitHub Desktop.
Convert a List of CompletableFutures to a CompletableFuture of a List
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static <T> CompletableFuture<List<T>> listOfFuturesToFutureList(final List<CompletableFuture<T>> listOfFutures) { | |
final Function<List<CompletableFuture<T>>, List<T>> transformFunction = futures -> futures.stream() | |
.map(CompletableFuture::join) | |
.collect(Collectors.toList()); | |
return CompletableFuture.allOf(listOfFutures.toArray(new CompletableFuture[0])) | |
.thenApply(v -> transformFunction.apply(listOfFutures)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment