Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method · added in Ruby 3.4
Fiber::Scheduler#blocking_operation_wait
blocking_operation_wait(work)
scheduler.c
View on GitHub ↗
VALUE rb_fiber_scheduler_blocking_operation_wait(VALUE scheduler, void* (*function)(void *), void *data, rb_unblock_function_t *unblock_function, void *data2, int flags, struct rb_fiber_scheduler_blocking_operation_state *state)
{
struct rb_blocking_operation_wait_arguments arguments = {
.function = function,
.data = data,
.unblock_function = unblock_function,
.data2 = data2,
.flags = flags,
.state = state
};
VALUE proc = rb_proc_new(rb_fiber_scheduler_blocking_operation_wait_proc, (VALUE)&arguments);
return rb_check_funcall(scheduler, id_blocking_operation_wait, 1, &proc);
}
Invoked by Ruby’s core methods to run a blocking operation in a non-blocking way.
Minimal suggested implementation is:
Example
def blocking_operation_wait(work) Thread.new(&work).join end
Ruby version changes
-
3.4
-
An optional
Fiber::Scheduler#blocking_operation_waithook allows blocking operations to be moved out of the event loop in order to reduce latency and improve multi-core processor utilization. [Feature #20876]
-