D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Fiber
/
Scheduler
/
Filename :
cdesc-Scheduler.ri
back
Copy
U:RDoc::NormalClass[iI"Scheduler:ETI"Fiber::Scheduler;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"hobject should comply to in order to be used as argument to 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 waiting on, 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"bAt the end of the current thread execution, the scheduler's method #scheduler_close is called;To;;0;[o; ;[I"XThe scheduler runs into a wait loop, checking all the blocked fibers (which it has ;TI"Tregistered on hook calls) and resuming them when the awaited resource is ready ;TI",(e.g. I/O ready or sleep time elapsed).;T@o; ;[I"LThis way concurrent execution will be achieved transparently for every ;TI"individual Fiber's code.;T@o; ;[I":Scheduler implementations are provided by gems, like ;TI".Async[https://github.com/socketry/async].;T@o; ;[I"Hook methods are:;T@o;;; ;[ o;;0;[o; ;[I"T#io_wait, #io_read, #io_write, #io_pread, #io_pwrite, and #io_select, #io_close;To;;0;[o; ;[I"#process_wait;To;;0;[o; ;[I"#kernel_sleep;To;;0;[o; ;[I"#timeout_after;To;;0;[o; ;[I"#address_resolve;To;;0;[o; ;[I"#block and #unblock;To;;0;[o; ;[I"#blocking_operation_wait;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 recommended that the scheduler implements 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"scheduler.c;T:0@omit_headings_from_table_of_contents_below0;0;0[ [ [ [[I" class;T[[:public[ [:protected[ [:private[ [I" instance;T[[;[[I"address_resolve;TI"scheduler.c;T[I" block;T@�[I"blocking_operation_wait;T@�[I" close;T@�[I" fiber;T@�[I" io_pread;T@�[I"io_pwrite;T@�[I"io_read;T@�[I"io_select;T@�[I"io_wait;T@�[I" io_write;T@�[I"kernel_sleep;T@�[I"process_wait;T@�[I"timeout_after;T@�[I"unblock;T@�[;[ [;[ [ [U:RDoc::Context::Section[i 0o;;[ ;0;0[I"cont.c;TI" Fiber;TcRDoc::NormalClass