Skip to main content

rb_fiber_transfer

Function rb_fiber_transfer 

Source
pub unsafe extern "C" fn rb_fiber_transfer(
    fiber: VALUE,
    argc: c_int,
    argv: *const VALUE,
) -> VALUE
Expand description

Transfers control to another fiber, resuming it from where it last stopped or starting it if it was not resumed before. The calling fiber will be suspended much like in a call to rb_fiber_yield.

The fiber which receives the transfer call treats it much like a resume call. Arguments passed to transfer are treated like those passed to resume.

The two style of control passing to and from fiber (one is rb_fiber_resume and rb_fiber_yield, another is rb_fiber_transfer to and from fiber) can’t be freely mixed.

  • If the Fiber’s lifecycle had started with transfer, it will never be able to yield or be resumed control passing, only finish or transfer back. (It still can resume other fibers that are allowed to be resumed.)

  • If the Fiber’s lifecycle had started with resume, it can yield or transfer to another Fiber, but can receive control back only the way compatible with the way it was given away: if it had transferred, it only can be transferred back, and if it had yielded, it only can be resumed back. After that, it again can transfer or yield.

If those rules are broken, [rb_eFiberError] is raised.

For an individual Fiber design, yield/resume is easier to use (the Fiber just gives away control, it doesn’t need to think about who the control is given to), while transfer is more flexible for complex cases, allowing to build arbitrary graphs of Fibers dependent on each other.

§@param[out] fiber Explicit control destination. @param[in] argc Number of objects of argv. @param[in] argv Passed to rb_fiber_resume. @exception [rb_eFiberError] (See above) @exception rb_eException What was raised using Fiber#raise. @return (See rb_fiber_resume for details)

Generated by rb-sys for Ruby mri-x86_64-linux-gnu-3.3.8