Improve Fiber#kill docs and simplify the NEWS entry to let the documentation explain

This commit is contained in:
Benoit Daloze 2023-12-06 22:44:37 +01:00
parent 7d052774bd
commit 0204523fe7
2 changed files with 11 additions and 3 deletions

View file

@ -40,7 +40,7 @@ Note: We're only listing outstanding class updates.
* Fiber * Fiber
* Introduce Fiber#kill, similar to Thread#kill. [[Bug #595]] * Introduce Fiber#kill. [[Bug #595]]
```ruby ```ruby
fiber = Fiber.new do fiber = Fiber.new do
while true while true

12
cont.c
View file

@ -3259,6 +3259,8 @@ rb_fiber_raise(VALUE fiber, int argc, const VALUE *argv)
* the exception, and the third parameter is an array of callback information. * the exception, and the third parameter is an array of callback information.
* Exceptions are caught by the +rescue+ clause of <code>begin...end</code> * Exceptions are caught by the +rescue+ clause of <code>begin...end</code>
* blocks. * blocks.
*
* Raises +FiberError+ if called on a Fiber belonging to another +Thread+.
*/ */
static VALUE static VALUE
rb_fiber_m_raise(int argc, VALUE *argv, VALUE self) rb_fiber_m_raise(int argc, VALUE *argv, VALUE self)
@ -3270,12 +3272,18 @@ rb_fiber_m_raise(int argc, VALUE *argv, VALUE self)
* call-seq: * call-seq:
* fiber.kill -> nil * fiber.kill -> nil
* *
* Terminates +fiber+ by raising an uncatchable exception, returning * Terminates +fiber+ by raising an uncatchable exception.
* the terminated Fiber. * It only terminates the given Fiber and no other Fiber, returning +nil+ to
* another Fiber if that Fiber was calling +fiber.resume+ or +fiber.transfer+.
*
* +Fiber#kill+ only interrupts another Fiber when it is in +Fiber.yield+.
* If called on the current Fiber then it raises that exception at the +Fiber#kill+ call site.
* *
* If the fiber has not been started, transition directly to the terminated state. * If the fiber has not been started, transition directly to the terminated state.
* *
* If the fiber is already terminated, does nothing. * If the fiber is already terminated, does nothing.
*
* Raises +FiberError+ if called on a Fiber belonging to another +Thread+.
*/ */
static VALUE static VALUE
rb_fiber_m_kill(VALUE self) rb_fiber_m_kill(VALUE self)