Issue #17331 has been updated by nevans (Nicholas Evans).

Description updated

updated description with more details .

I don't know whether the API should be explicit or implicit. I slightly favor the explicit version, because (in my mental model) resume vs transfer (generator vs full coroutine) are more different from each other than resume and raise (which are merely two resume values for a fiber, two different results for `Fiber.yield`). But those distinctions can definitely be blurred. ioquatrix made the good point that "There is no point adding an option for which only introduces failure cases (unless that has value...)".

----------------------------------------
Feature #17331: Let Fiber#raise work with transferring fibers
https://bugs.ruby-lang.org/issues/17331#change-88651

* Author: nevans (Nicholas Evans)
* Status: Open
* Priority: Normal
----------------------------------------
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`.

```ruby
yielding_fiber.raise "message"
transferring_fiber.raise "message", transfer: true
```

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.


```ruby
yielding_fiber.raise "message"
transferring_fiber.raise "message", transfer: true
```

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



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>