Project

General

Profile

Actions

Bug #17331

closed

Let Fiber#raise work with transferring fibers

Added by nevans (Nicholas Evans) about 1 year ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:100925]

Description

It would be useful to use raise on transferring fibers just as we can with yielding fibers.

I've added a transfer kwarg, so it is not automatic; the caller must know how to handle the fiber. If you call a yielding fiber with transfer: true or a transferring fiber without transfer: true, a FiberError will be raised. Resuming fibers still raise a FiberError.

yielding_fiber.raise "message"
# => resumes and raises from the last Fiber.yield

transferring_fiber.raise "message", transfer: true
# => transfers and raises from the last fiber.transfer

resuming_fiber.raise "message"
# => raises FiberError

Implementation: https://github.com/ruby/ruby/pull/3783

I also implemented a second version that implicitly and automatically selects rb_fiber_transfer_kw for transferring fibers and rb_fiber_resume_kw for yielding fibers. The implicit version also raises FiberError on resuming fibers.

yielding_fiber.raise "message"
# => resumes and raises from the last Fiber.yield

transferring_fiber.raise "message"
# => transfers and raises from the last fiber.transfer

resuming_fiber.raise "message"
# => raises FiberError

Alternate implicit implementation: https://github.com/ruby/ruby/pull/3795

I slightly prefer the explicit version, but I'm okay with the implicit version.


Related issues

Related to Ruby master - Feature #17325: Adds Fiber#cancel, which forces a Fiber to break/returnOpenActions
Actions

Also available in: Atom PDF