Futures vs CompletableFuture
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
see why Future is limiting and what CompletableFuture adds.
Planned topics
Future.get()blocks; there is no way to say "when done, do X".CompletableFuture<T>is a future you can chain, combine, and complete manually.supplyAsyncruns a value-producing task;runAsynca no-result task.- Each stage returns a new future; build a pipeline instead of blocking.
- Block only at the edge of the system, if at all.
Draft outline details
Demonstration
CompletableFuture<Product> p = CompletableFuture.supplyAsync(() -> productClient.get(id), ioPool);Check your understanding
What can a CompletableFuture do that Future cannot?
Show answer
Chain callbacks and combine results without blocking.
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.