Repository navigation
feat(cancellation): add cooperative cancellation tokens - #488
malikrehanmulla1048 wants to merge 4 commits into
Conversation
Co-authored-by: Copilot <[email protected]>
|
Thanks for picking this up for review, @orthur2! I noticed the CI / Required and Miri checks failed—I'll inspect the logs, run cargo x check, cargo x test, and cargo x lint locally, and push a fix shortly. |
| @@ -1 +1,20 @@ | |||
| <!-- | |||
There was a problem hiding this comment.
This breaks the Windows checkout. The file is a symlink to ../MIGRATE.md, and the header becomes part of its target. Could we revert it?
| fn test_dropping_uncancelled_source_does_not_cancel_or_wake_tokens() { | ||
| let source = CancellationSource::new(); | ||
| let token = source.token(); | ||
| drop(source); |
There was a problem hiding this comment.
There's no registered waiter yet when drop(source) runs, so this test would still pass if dropping the source woke waiters. Could we poll the wait to Pending first, then check !wait.is_woken() after the drop?
orthur2
left a comment
There was a problem hiding this comment.
If an application already has a ShutdownWatch and calls a library that takes a CancellationToken, should it be able to pass the same cancellation signal through?
Summary
Add an opt-in
cancellationfeature with aCancellationSourcefor explicitly requesting cancellation and cloneableCancellationTokenobservers for querying or awaiting that request. This supports broadcasting a cooperative stop signal to background work without requiring participant-completion tracking.Refs #223.
Design Notes
cancelled(), or create an owned wait withcancelled_owned().Latchfor shared state and waiter notification. It does not spawn, interrupt, or join tasks.shutdownremains unchanged in this proposal. Feedback is welcome on whether cancellation should remain separate or become part of a future shutdown redesign.Validation
cargo x check,cargo x test, andcargo x lintbefore requesting final review.