Skip to content

Add specs for where Fiber#transfer returns control - #1397

Open
sampokuokkanen wants to merge 3 commits into
ruby:masterfrom
sampokuokkanen:fiber-transfer-return-control
Open

Add specs for where Fiber#transfer returns control#1397
sampokuokkanen wants to merge 3 commits into
ruby:masterfrom
sampokuokkanen:fiber-transfer-return-control

Conversation

@sampokuokkanen

Copy link
Copy Markdown
Contributor

A Fiber entered by Fiber#transfer has no resumer, so when it finishes or is killed, control goes to the innermost Fiber reachable from the root Fiber by following resumes, which is not necessarily the Fiber that transferred. Also covers a transferring Fiber that was itself entered by Fiber#raise.

A Fiber entered by Fiber#transfer has no resumer, so when it finishes or
is killed, control goes to the innermost Fiber reachable from the root
Fiber by following resumes, which is not necessarily the Fiber that
transferred. Also covers a transferring Fiber that was itself entered by
Fiber#raise.
Fiber#kill unwinds by transferring into the fiber, so it returns the
fiber rather than nil, is a no-op on one that is already dead, and runs
the ensure block while the fiber is still current and alive. An exception
raised from that ensure block reaches the caller of kill, and killing a
fiber belonging to another Thread raises FiberError.

Also covers two cases where kill and transfer meet: killing a fiber from
the fiber it transferred to, and killing a fiber whose ensure block
transfers away.
Kill a Fiber twice and the second call returns false, not the Fiber.
Running to completion does not count as killed, so one that ended on its
own still returns itself.

Raising into the Fiber that resumed you delivers the exception there and
leaves you suspended. The resume it interrupts never returns, so the rest
of the raising Fiber never runs.
sampokuokkanen added a commit to sampokuokkanen/jruby that referenced this pull request Sep 10, 2026
Same examples as ruby/spec#1397, word for word, so the periodic sync of
spec/ruby brings nothing new. They cover where control goes when a fiber
entered by transfer finishes, is killed, or transferred from a fiber that
Fiber#raise entered, plus what Fiber#kill returns and when it refuses.

Three stay tagged: killing a fiber does not yet run its ensure block
synchronously, so an exception raised there never reaches the caller and
a fiber killed mid-transfer keeps running.
sampokuokkanen added a commit to sampokuokkanen/jruby that referenced this pull request Sep 10, 2026
Same examples as the third commit on ruby/spec#1397, so the periodic sync
of spec/ruby brings nothing new. Both are tagged: kill returns the fiber
on a second call instead of false, and raising into the fiber that resumed
us hands it our return value instead of leaving it suspended.
sampokuokkanen added a commit to sampokuokkanen/jruby that referenced this pull request Sep 10, 2026
Same examples as ruby/spec#1397, word for word, so the periodic sync of
spec/ruby brings nothing new. They cover where control goes when a fiber
entered by transfer finishes, is killed, or transferred from a fiber that
Fiber#raise entered, plus what Fiber#kill returns and when it refuses.

Three stay tagged: killing a fiber does not yet run its ensure block
synchronously, so an exception raised there never reaches the caller and
a fiber killed mid-transfer keeps running.
sampokuokkanen added a commit to sampokuokkanen/jruby that referenced this pull request Sep 10, 2026
Same examples as the third commit on ruby/spec#1397, so the periodic sync
of spec/ruby brings nothing new. Both are tagged: kill returns the fiber
on a second call instead of false, and raising into the fiber that resumed
us hands it our return value instead of leaving it suspended.
sampokuokkanen added a commit to sampokuokkanen/jruby that referenced this pull request Sep 10, 2026
Same examples as ruby/spec#1397, word for word, so the periodic sync of
spec/ruby brings nothing new. They cover where control goes when a fiber
entered by transfer finishes, is killed, or transferred from a fiber that
Fiber#raise entered, plus what Fiber#kill returns and when it refuses.

Three stay tagged: killing a fiber does not yet run its ensure block
synchronously, so an exception raised there never reaches the caller and
a fiber killed mid-transfer keeps running.
sampokuokkanen added a commit to sampokuokkanen/jruby that referenced this pull request Sep 10, 2026
Same examples as the third commit on ruby/spec#1397, so the periodic sync
of spec/ruby brings nothing new. Both are tagged: kill returns the fiber
on a second call instead of false, and raising into the fiber that resumed
us hands it our return value instead of leaving it suspended.
sampokuokkanen added a commit to sampokuokkanen/jruby that referenced this pull request Sep 10, 2026
Same examples as ruby/spec#1397, word for word, so the periodic sync of
spec/ruby brings nothing new. They cover where control goes when a fiber
entered by transfer finishes, is killed, or transferred from a fiber that
Fiber#raise entered, plus what Fiber#kill returns and when it refuses.

Three stay tagged: killing a fiber does not yet run its ensure block
synchronously, so an exception raised there never reaches the caller and
a fiber killed mid-transfer keeps running.
sampokuokkanen added a commit to sampokuokkanen/jruby that referenced this pull request Sep 10, 2026
Same examples as the third commit on ruby/spec#1397, so the periodic sync
of spec/ruby brings nothing new. Both are tagged: kill returns the fiber
on a second call instead of false, and raising into the fiber that resumed
us hands it our return value instead of leaving it suspended.
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