Created
June 28, 2011 05:47
-
-
Save SaitoWu/1050566 to your computer and use it in GitHub Desktop.
ruby fibers exercise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fiber' | |
fib = Fiber.new do | |
v = 0 | |
loop do | |
v += 1 | |
Fiber.yield v | |
v.times { print "-"} | |
puts v | |
end | |
end | |
20.times{fib.resume} | |
foo, bar, baz = nil | |
foo = Fiber.new do | |
p 'hello foo' | |
bar.transfer | |
end | |
bar = Fiber.new do | |
p 'hello bar' | |
baz.transfer | |
end | |
baz = Fiber.new do | |
p 'hello baz' | |
foo.transfer | |
end | |
foo.resume |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment