Method: Fiber#kill
- Defined in:
- cont.c
#kill ⇒ nil
Terminates the fiber by raising an uncatchable exception. It only terminates the given fiber and no other fiber, returning nil
to another fiber if that fiber was calling #resume or #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 is already terminated, does nothing.
Raises FiberError if called on a fiber belonging to another thread.
3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 |
# File 'cont.c', line 3216
static VALUE
rb_fiber_m_kill(VALUE self)
{
rb_fiber_t *fiber = fiber_ptr(self);
if (fiber->killed) return Qfalse;
fiber->killed = 1;
if (fiber->status == FIBER_CREATED) {
fiber->status = FIBER_TERMINATED;
}
else if (fiber->status != FIBER_TERMINATED) {
if (fiber_current() == fiber) {
fiber_check_killed(fiber);
}
else {
fiber_raise(fiber_ptr(self), Qnil);
}
}
return self;
}
|