Skip to content

Instantly share code, notes, and snippets.

@DeepSpawn
Last active July 6, 2016 22:05
Show Gist options
  • Save DeepSpawn/f3f33ffb4e51580666b0985a4d8a7781 to your computer and use it in GitHub Desktop.
Save DeepSpawn/f3f33ffb4e51580666b0985a4d8a7781 to your computer and use it in GitHub Desktop.
public static <T> CompletableFuture<List<T>> sequence(final List<CompletableFuture<T>> futures) {
return CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()]))
.thenApply(unit -> futures
.stream()
.map(CompletableFuture::join)
.collect(toList()));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment