static VALUE enumerator_next(VALUE obj) { struct enumerator *e = enumerator_ptr(obj); VALUE curr, v; curr = rb_fiber_current(); if (!e->fib || !rb_fiber_alive_p(e->fib)) { next_init(obj, e); } v = rb_fiber_resume(e->fib, 1, &curr); if (e->no_next) { e->fib = 0; e->dst = Qnil; e->no_next = Qfalse; rb_raise(rb_eStopIteration, "iteration reached at end"); } return v; }
static VALUE get_next_values(VALUE obj, struct enumerator *e) { VALUE curr, vs; if (e->stop_exc) rb_exc_raise(e->stop_exc); curr = rb_fiber_current(); if (!e->fib || !rb_fiber_alive_p(e->fib)) { next_init(obj, e); } vs = rb_fiber_resume(e->fib, 1, &curr); if (e->stop_exc) { e->fib = 0; e->dst = Qnil; e->lookahead = Qundef; e->feedvalue = Qundef; rb_exc_raise(e->stop_exc); } return vs; }