Slide 44
Slide 44 text
(Completable)Future
The Future interface was introduced in Java 5 to model an asynch
computation and then provide an handle to a result that will be
made available at some point in the future.
CompletableFuture introduced in Java 8 added
fluent composability, callbacks and more.
CompletableFuture
.supplyAsync(() -> shop.getPrice(product))
.thenCombine(CompletableFuture.supplyAsync(
() -> exchange.getRate(Money.EUR,
Money.USD)),
(price, rate) -> price * rate)
.thenAccept(System.out::println);
+ Non-blocking composition
+ Freely sharable
+ Can recover from failure
- Callback Hell
- Debugging can be hard
- Closing over mutable state