Skip to content

Instantly share code, notes, and snippets.

@fromdev
Created August 15, 2019 02:48
Show Gist options
  • Save fromdev/0a7c869ca1b05701580e0041f5ada14e to your computer and use it in GitHub Desktop.
Save fromdev/0a7c869ca1b05701580e0041f5ada14e to your computer and use it in GitHub Desktop.
SampleAsyncCallInSequence - Supplier Lambda Example Code
MyClass myobject = new MyClass();
CompletableFuture<Data> dataCompletableFuture1 = CompletableFuture.supplyAsync(() -> myobject.getData1()); // first Async call
CompletableFuture<Data> dataCompletableFuture2 = CompletableFuture.supplyAsync(() -> myobject.getData2()); // second Async call
CompletableFuture<Data> dataCompletableFuture3 = CompletableFuture.supplyAsync(() -> myobject.getData3()); // third Async call
//Now the code to combine in sequence
dataCompletableFuture1
.thenCombine(dataCompletableFuture2, Aggregator::combine)
.thenCombine(dataCompletableFuture3, Aggregator::combine);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment