⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.133
Server IP:
185.119.109.197
Server:
Linux managedhosting.chostar.me 5.15.0-160-generic #170-Ubuntu SMP Wed Oct 1 10:06:56 UTC 2025 x86_64
Server Software:
Apache
PHP Version:
8.1.33
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
proc
/
self
/
root
/
usr
/
share
/
ri
/
3.0.0
/
system
/
Fiber
/
View File Name :
cdesc-Fiber.ri
U:RDoc::NormalClass[iI" Fiber:ET@I"Object;To:RDoc::Markup::Document:@parts[o;;[$o:RDoc::Markup::Paragraph;[ I"EFibers are primitives for implementing light weight cooperative ;TI"Mconcurrency in Ruby. Basically they are a means of creating code blocks ;TI"Lthat can be paused and resumed, much like threads. The main difference ;TI"Nis that they are never preempted and that the scheduling must be done by ;TI"#the programmer and not the VM.;To:RDoc::Markup::BlankLine o; ;[ I"OAs opposed to other stackless light weight concurrency models, each fiber ;TI"Jcomes with a stack. This enables the fiber to be paused from deeply ;TI"Dnested function calls within the fiber block. See the ruby(1) ;TI"9manpage to configure the size of the fiber stack(s).;T@o; ;[ I"KWhen a fiber is created it will not run automatically. Rather it must ;TI"?be explicitly asked to run using the Fiber#resume method. ;TI"FThe code running inside the fiber can give up control by calling ;TI"EFiber.yield in which case it yields control back to caller (the ;TI"!caller of the Fiber#resume).;T@o; ;[I"JUpon yielding or termination the Fiber returns the value of the last ;TI"executed expression;T@o; ;[I"For instance:;T@o:RDoc::Markup::Verbatim;[ I"fiber = Fiber.new do ;TI" Fiber.yield 1 ;TI" 2 ;TI" end ;TI" ;TI"puts fiber.resume ;TI"puts fiber.resume ;TI"puts fiber.resume ;T:@format0o; ;[I"
produces
;T@o;;[I"1 ;TI"2 ;TI"#FiberError: dead fiber called ;T;0o; ;[ I"HThe Fiber#resume method accepts an arbitrary number of parameters, ;TI"Dif it is the first call to #resume then they will be passed as ;TI"Eblock arguments. Otherwise they will be the return value of the ;TI"call to Fiber.yield;T@o; ;[I" Example:;T@o;;[I""fiber = Fiber.new do |first| ;TI"& second = Fiber.yield first + 2 ;TI" end ;TI" ;TI"puts fiber.resume 10 ;TI"!puts fiber.resume 1_000_000 ;TI"Kputs fiber.resume "The fiber will be dead before I can cause trouble" ;T;0o; ;[I"
produces
;T@o;;[I"12 ;TI" 1000000 ;TI"#FiberError: dead fiber called ;T;0S:RDoc::Markup::Heading: leveli: textI"Non-blocking Fibers;T@o; ;[I"PSince Ruby 3.0, the concept of
non-blocking fiber
was introduced. ;TI"PNon-blocking fiber, when reaching any potentially blocking operation (like ;TI"Nsleep, wait for another process, wait for I/O data to be ready), instead ;TI"Mof just freezing itself and all execution in the thread, yields control ;TI"Uto other fibers, and allows the
scheduler
to handle waiting and waking ;TI".(resuming) the fiber when it can proceed.;T@o; ;[ I"QFor Fiber to behave as non-blocking, it should be created in Fiber.new with ;TI"N
blocking: false
(which is the default now), and Fiber.scheduler ;TI"Nshould be set with Fiber.set_scheduler. If Fiber.scheduler is not set in ;TI"Qthe current thread, blocking and non-blocking fiber's behavior is identical.;T@o; ;[I"QRuby doesn't provide a scheduler class: it is expected to be implemented by ;TI":the user and correspond to Fiber::SchedulerInterface.;T@o; ;[I"SThere is also Fiber.schedule method, which is expected to immediately perform ;TI"Spassed block in a non-blocking manner (but its actual implementation is up to ;TI"the scheduler).;T: @fileI"cont.c;T:0@omit_headings_from_table_of_contents_below0;0;0[ [ [ [[I" class;T[[:public[[I"blocking?;TI"cont.c;T[I"current;T@z[I"new;T@z[I" schedule;T@z[I"scheduler;T@z[I"set_scheduler;T@z[I" yield;T@z[:protected[ [:private[ [I" instance;T[[;[[I"alive?;T@z[I"backtrace;T@z[I"backtrace_locations;T@z[I"blocking?;T@z[I"inspect;T@z[I" raise;T@z[I"resume;T@z[I" to_s;T@z[I" transfer;T@z[;[ [;[ [ [U:RDoc::Context::Section[i 0o;;[ ;0;0[@n@ncRDoc::TopLevel