D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Fiber
/
Filename :
new-c.ri
back
Copy
U:RDoc::AnyMethod[iI"new:ETI"Fiber::new;TT:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"OCreates new Fiber. Initially, the fiber is not running and can be resumed ;TI"Mwith #resume. Arguments to the first #resume call will be passed to the ;TI"block:;To:RDoc::Markup::BlankLine o:RDoc::Markup::Verbatim; [I" f = Fiber.new do |initial| ;TI" current = initial ;TI" loop do ;TI"- puts "current: #{current.inspect}" ;TI" current = Fiber.yield ;TI" end ;TI" end ;TI".f.resume(100) # prints: current: 100 ;TI"4f.resume(1, 2, 3) # prints: current: [1, 2, 3] ;TI".f.resume # prints: current: nil ;TI"# ... and so on ... ;T:@format0o; ; [I"PIf <tt>blocking: false</tt> is passed to <tt>Fiber.new</tt>, _and_ current ;TI"Othread has a Fiber.scheduler defined, the Fiber becomes non-blocking (see ;TI"2"Non-blocking Fibers" section in class docs).;T@o; ; [I"QIf the <tt>storage</tt> is unspecified, the default is to inherit a copy of ;TI"Hthe storage from the current fiber. This is the same as specifying ;TI"<tt>storage: true</tt>.;T@o;; [I"Fiber[:x] = 1 ;TI"Fiber.new do ;TI" Fiber[:x] # => 1 ;TI" Fiber[:x] = 2 ;TI"end.resume ;TI"Fiber[:x] # => 1 ;T; 0o; ; [I"LIf the given <tt>storage</tt> is <tt>nil</tt>, this function will lazy ;TI"Dinitialize the internal storage, which starts as an empty hash.;T@o;; [ I"Fiber[:x] = "Hello World" ;TI" Fiber.new(storage: nil) do ;TI" Fiber[:x] # nil ;TI" end ;T; 0o; ; [I"OOtherwise, the given <tt>storage</tt> is used as the new fiber's storage, ;TI"(and it must be an instance of Hash.;T@o; ; [I"OExplicitly using <tt>storage: true</tt> is currently experimental and may ;TI"change in the future.;T: @fileI"cont.c;T:0@omit_headings_from_table_of_contents_below0I"HFiber.new(blocking: false, storage: true) { |*args| ... } -> fiber ;T0[ I"(*args);T@BFI" Fiber;TcRDoc::NormalClass00