ReviewOS

also looking at this

home-lang/home

fix(async): preserve cancellation and add revision-aware job gate

#914
Merged chris wants to merge feat/camera-jobs into main
6 files +217 -20
packages/async/README.mdmodified+25-0
Changes to packages/async/README.md
@@ -96,3 +96,28 @@ scripts/async-runtime-tsan.sh 1 10000 1024
9696## License
9797
9898Part of the Home programming language project.
99
100## Terminal job state and event completion
101
102Task cancellation is terminal: an in-flight future poll returning Ready or Pending
103cannot overwrite Cancelled, and cancelling an already completed/failed task does
104not replace its result. JoinHandle.await returns TaskFailed immediately for a
105failed task. Cancellation does not interrupt a currently executing poll or make
106its storage safe to free; quiesce/join the polling owner before deinit.
107
108`CompletionGate` is a small allocation-free two-phase event-job helper. It ignores
109events from older revisions and terminal outcomes before an active phase has been
110observed. Success, failure, cancellation and stop are immutable terminal states.
111The caller owns synchronization; it is not an executor or a generic Future.
112zig-utils/zig-camera uses this Home module for autofocus scan gating under its
113native session mutex without allocating or running consumer work in callbacks.
114
115Regression tests cover cancellation between poll reservation and both Ready and
116Pending results, late cancellation, failed joins, stale event revisions, and
117terminal immutability. Focused task/gate tests pass on Zig 0.15.2 and Home's current
1180.17 development toolchain. The complete async root suite also passes locally with
119its threading_futex module supplied:
120
121```sh
122zig test -lc --dep threading_futex -Mroot=packages/async/src/async.zig -Mthreading_futex=packages/runtime/src/threading/Futex.zig
123```