File: //usr/share/ri/3.0.0/system/Fiber/SchedulerInterface/cdesc-SchedulerInterface.ri
U:RDoc::NormalClass[iI"SchedulerInterface:ETI"Fiber::SchedulerInterface;TI"Object;To:RDoc::Markup::Document:@parts[o;;[o:RDoc::Markup::Paragraph;[ I"VThis is not an existing class, but documentation of the interface that Scheduler ;TI"Yobject should comply in order to be used as Fiber.scheduler and handle non-blocking ;TI"]fibers. See also the "Non-blocking fibers" section in Fiber class docs for explanations ;TI"of some concepts.;To:RDoc::Markup::BlankLine o; ;[I"BScheduler's behavior and usage are expected to be as follows:;T@o:RDoc::Markup::List:
@type:BULLET:@items[ o:RDoc::Markup::ListItem:@label0;[o; ;[I"XWhen the execution in the non-blocking Fiber reaches some blocking operation (like ;TI"Vsleep, wait for a process, or a non-ready I/O), it calls some of the scheduler's ;TI" hook methods, listed below.;To;;0;[o; ;[I"ZScheduler somehow registers what the current fiber is waited for, and yields control ;TI"[to other fibers with Fiber.yield (so the fiber would be suspended while expecting its ;TI"Bwait to end, and other fibers in the same thread can perform);To;;0;[o; ;[I"XAt the end of the current thread execution, the scheduler's method #close is called;To;;0;[o; ;[I"XThe scheduler runs into a wait loop, checking all the blocked fibers (which it has ;TI"Yregistered on hook calls) and resuming them when the awaited resource is ready (I/O ;TI"ready, sleep time passed).;T@o; ;[I"VA typical implementation would probably rely for this closing loop on a gem like ;TI"CEventMachine[https://github.com/eventmachine/eventmachine] or ;TI".Async[https://github.com/socketry/async].;T@o; ;[I"[This way concurrent execution will be achieved in a way that is transparent for every ;TI"individual Fiber's code.;T@o; ;[I"Hook methods are:;T@o;;;
;[
o;;0;[o; ;[I"
#io_wait;To;;0;[o; ;[I"#process_wait;To;;0;[o; ;[I"#kernel_sleep;To;;0;[o; ;[I"#block and #unblock;To;;0;[o; ;[I"Z(the list is expanded as Ruby developers make more methods having non-blocking calls);T@o; ;[
I"[When not specified otherwise, the hook implementations are mandatory: if they are not ;TI"`implemented, the methods trying to call hook will fail. To provide backward compatibility, ;TI"]in the future hooks will be optional (if they are not implemented, due to the scheduler ;TI"]being created for the older Ruby version, the code which needs this hook will not fail, ;TI"1and will just behave in a blocking fashion).;T@o; ;[I"\It is also strongly suggested that the scheduler implement the #fiber method, which is ;TI"$delegated to by Fiber.schedule.;T@o; ;[I"RSample _toy_ implementation of the scheduler can be found in Ruby's code, in ;TI"%<tt>test/fiber/scheduler.rb</tt>;T:
@fileI"cont.c;T:0@omit_headings_from_table_of_contents_below0;0;0[ [ [ [[I"
class;T[[:public[ [:protected[ [:private[ [I"
instance;T[[;[[I"
block;TI"cont.c;T[I"
close;T@[I"
fiber;T@[I"io_wait;T@[I"kernel_sleep;T@[I"process_wait;T@[I"unblock;T@[;[ [;[ [ [U:RDoc::Context::Section[i 0o;;[ ;0;0[@jI"
Fiber;TcRDoc::NormalClass