Skip to content

Instantly share code, notes, and snippets.

@SaitoWu
Created June 28, 2011 05:47
Show Gist options
  • Save SaitoWu/1050566 to your computer and use it in GitHub Desktop.
Save SaitoWu/1050566 to your computer and use it in GitHub Desktop.
ruby fibers exercise
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