completablefuture: CompletableFuture module (thenApply vs thenCompose and the serial trap, which thread runs a stage incl. join() running dependents, CompletionException wrapping, orTimeout/cancel not stopping work, allOf/anyOf with fail-fast and first-success helpers, virtual-thread timings, StructuredTaskScope preview error), 26 contract tests

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b3dRuKRhrHFPzWSSxr
This commit is contained in:
Ankur Mhatre
2026-11-22 18:56:47 +05:30
co-authored by Claude Sonnet 5.5
parent 59a5435825
commit 9c2ae10d7f
25 changed files with 1335 additions and 0 deletions
@@ -0,0 +1,19 @@
== 1. allOf returns CompletableFuture<Void> - you collect results yourself
collected: [a, b, c]
== 2. allOf with one early failure: it waits for the slow one anyway
allOf failed with: CompletionException <- cause IllegalStateException: failed after 50 ms
after 401 ms (the failure itself happened at 50 ms)
slow task finished by then? true
== 3. allOrFailFast: fail at the first failure, but nothing is cancelled
failed with: CompletionException <- cause IllegalStateException: failed after 50 ms
after 50 ms
slow task finished by then? false
slow task finished 450 ms later? true
== 4. anyOf returns the first COMPLETION, and a failure counts
anyOf failed with: CompletionException <- cause IllegalStateException: failed after 30 ms
== 5. firstSuccess: skip failures, take the first value
firstSuccess result: slow ok