Skip to content

feat(cancellation): add cooperative cancellation tokens - #488

Open
malikrehanmulla1048 wants to merge 1 commit into
apache:mainfrom
malikrehanmulla1048:feat/cooperative-cancellation
Open

malikrehanmulla1048 wants to merge 1 commit into
apache:mainfrom
malikrehanmulla1048:feat/cooperative-cancellation

Conversation

@malikrehanmulla1048

Copy link
Copy Markdown

Summary

Add an opt-in cancellation feature with a CancellationSource for explicitly requesting cancellation and cloneable CancellationToken observers 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

  • Cancellation is sticky and idempotent. Tokens can query the state, await it with cancelled(), or create an owned wait with cancelled_owned().
  • Dropping a pending wait affects only that observer. Dropping an uncancelled source does not request cancellation; its tokens remain uncancelled and pending waits remain pending.
  • The implementation reuses Latch for shared state and waiter notification. It does not spawn, interrupt, or join tasks.
  • shutdown remains unchanged in this proposal. Feedback is welcome on whether cancellation should remain separate or become part of a future shutdown redesign.

Validation

  • Added integration tests for sticky requests, multiple observers, wait cancellation, owned waits, source drop, and racing wait registration with cancellation.
  • Checks have not yet been run in this environment. Update this section with the results of cargo x check, cargo x test, and cargo x lint before requesting final review.

@orthur2
orthur2 self-requested a review November 29, 2026 03:34
@malikrehanmulla1048

Copy link
Copy Markdown
Author

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant