Composing stages
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
pick the right combinator.
Planned topics
thenApply(fn): transform the result (map).thenCompose(fn): fn returns another future; flattens (flatMap). Use for dependent calls.thenCombine(other, fn): join two independent futures.allOf(...): completes when all do; it returnsVoid, so read each future afterwards.anyOftakes the first.thenAccept/thenRunfor side effects at the end.
Draft outline details
Demonstration
var page = product.thenCombine(stock, PageParts::new)
.thenCombine(reviews, (parts, r) -> parts.with(r));
CompletableFuture<Order> o = userF.thenCompose(u -> loadLastOrder(u.id()));Check your understanding
Which combinator for "call B using A's result, where B is async"?
Show answer
thenCompose.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.