Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Explore #223 with an opt-in
cancellationAPI: a non-cloneableCancellationSourceissues explicit stop requests, while cloneableCancellationTokenobservers query or await them. A runnable replica-lookup example cancels redundant work after the first answer and joins task handles separately.This is a draft prototype for API discussion, not a decision to add another primitive. It includes seven behavior tests, feature wiring, API documentation, and a changelog entry.
Validation:
cargo x test(626 tests),cargo x check(27 feature configurations),cargo x lint,cargo x build --locked, thecancel_lookupsexample, and the seven cancellation tests on Rust 1.86.0.Design Notes
Contract. Only the source can cancel; sharing it with
Arcexplicitly delegates that authority. Requests are sticky and idempotent, including concurrent calls. Tokens supportis_cancelled(), borrowedcancelled()waits, andcancelled_owned()futures that outlive the token. Dropping one wait removes only its registration. Cancellation requests neither interrupt work nor imply task completion.Source drop. Dropping an uncancelled source does not cancel or wake observers. Their query stays false and existing or future waits remain pending indefinitely. This treats cancellation as an optional stop request raced with work that can finish normally. A request already issued survives source destruction. There is no separate closed state or abandonment error in this prototype.
ShutdownWatchArc<Latch>with count oneCompletion<()>Abandonedon producer drop. Prefer it when producer disappearance must wake observers.Implementation. Both handles wrap the same
Arc<Latch>; the feature enableslatch. This reuses registration, cancellation cleanup, and wake handling without another state machine. A separate signal implementation would duplicate those mechanisms. Rebuilding shutdown on this API can wait until the public contract is accepted; its current implementation is unchanged.Ecosystem. Tokio's token combines observing and cancelling in every clone. This proposal separates those capabilities. Explicit source destruction without a request also has precedent in .NET's
CancellationTokenSource.Dispose; this does not adopt .NET's other disposal semantics.Questions for review. Existing primitives can express this scenario: the benefit is a smaller, purpose-specific caller contract, not new coordination power. Is that worth two public types? Is permanently pending after source loss preferable to a distinct closure result? Is explicit
Arc<CancellationSource>sufficient for multiple controllers? Hierarchy, cancellation reasons, signal composition, timers, and task ownership remain outside this draft.