Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alfredrichards/4931ecce6ab3f78666b92e764d3c20c9 to your computer and use it in GitHub Desktop.
Save alfredrichards/4931ecce6ab3f78666b92e764d3c20c9 to your computer and use it in GitHub Desktop.
Combining two CompletableFuture objects in Java
// callback is executed after the completion of
// completableFuture1, completableFuture2
completableFuture1.thenCombine(completableFuture2, biFunction);
completableFuture1.thenAcceptBoth(completableFuture2, biConsumer);
completableFuture1.runAfterBoth(completableFuture2, runnable);
// callback is executed after the completion of
// either one of completableFuture1 or completableFuture2
completableFuture1.applyToEither(completableFuture2, function);
completableFuture1.acceptEither(completableFuture2, consumer);
completableFuture1.runAfterEither(completableFuture2, runnable);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment