RubyPulse Episode 0.36 - fibers
Fibers are primitives for implementing light weight cooperative concurrency in Ruby.
this will create a fiber that returns an input + an initial
$ irb1.9
irb:01:0> f = Fiber.new do |initial|
irb:02:1* a = 0
irb:03:1> loop {
irb:04:2* a = Fiber.yield a + initial
irb:05:2> }
irb:06:1> end
=> #
irb:07:0> f.resume 10
=> 10
irb:08:0> f.resume 111
=> 121
irb:09:0> f.resume 111
=> 121
irb:10:0> f.resume 1111
=> 1121
irb:11:0> f.resume 11111
=> 11121
Links for this episode
| RubyDoc |
Tags : ruby, 1.9, fibers