`src/cancel.rs` — `CancelSignal`
The cooperative cancellation flag, shareable as Arc<CancelSignal>, honored at every level of the engine.
Key items
cancel()— fire; idempotent; wakes all waiters.is_cancelled()— non-blocking poll.notified().await— race-free async wait; completes immediately if already fired.reset()— swap in a fresh token (the underlying tokioCancellationTokenis one-shot by design).
Behavior notes
- Wraps
tokio_util::sync::CancellationTokenprecisely to avoid the check-then-act race of hand-rolledAtomicBool+Notify. - The engine re-arms in
finalize()— after the run observed the cancel — so a cancel arriving between runs is observed by exactly one run, then cleared. One cancel can never permanently kill an agent. - A task already waiting on the old token when
reset()happens still completes against the old (fired) token. - Lock poisoning is recovered (single-value data — the
recover_guardpolicy).
Deep dive: Cancellation.