feature(fiber): add Cancel.make_child for linked cancellation#15364
Open
rgrinberg wants to merge 1 commit into
Open
feature(fiber): add Cancel.make_child for linked cancellation#15364rgrinberg wants to merge 1 commit into
rgrinberg wants to merge 1 commit into
Conversation
[Cancel.make_child parent] returns a new cancellation that is fired whenever [parent] is fired (but not the other way around). A parent tracks its children and [fire]/[fire'] propagate cancellation down the tree; a child detaches itself from its parent when it fires so that short-lived children attached to a long-lived parent do not leak. Signed-off-by: Rudi Grinberg <me@rgrinberg.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Adds
Fiber.Cancel.make_child, a way to link cancellations together:make_child parentreturns a new cancellation that is fired wheneverparentisfired (but not the other way around). This makes it possible to build trees of
cancellations where cancelling a parent propagates to all of its descendants.
Details
Not_cancelledcancellation now tracks itschildrenand itsparent.fireandfire'walk the child tree, so firing a node fires its wholesubtree. The order in which a parent's and its children's handlers run is
unspecified.
attached to a long-lived parent do not accumulate. (A child is otherwise
retained until it or its parent is fired, or the parent is collected.)
with_handler's behaviour is unchanged.Tests
src/fiber/test/cancel_tests.mlgains three expect tests covering: