Practice ยท 2 of 3
Compose, don't block
Implement with CompletableFuture (returned before completion, joined by the test):
1. static CompletableFuture<Integer> combined() โ two async supplies (return 20 and 22), combined with thenCombine into their sum.
2. static CompletableFuture<Integer> chained() โ an async 3, thenCompose to double it, thenApply to add 4 (=> 10).
3. static CompletableFuture<Integer> recovered() โ an async that throws, then exceptionally returning -1.
4. static CompletableFuture<Integer> bounded() โ async sleeping 50ms then returning 7, with orTimeout(10, MILLISECONDS) and exceptionally returning -1 (timeout path exercised).
Difficulty: advanced
Press Submit to check your solution.
Back to lesson: Practice: Executor & VT drills