Skip to content

Instantly share code, notes, and snippets.

@hakobe
Created February 1, 2009 06:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakobe/55811 to your computer and use it in GitHub Desktop.
Save hakobe/55811 to your computer and use it in GitHub Desktop.
require 'fiber'
f1 = nil
f2 = nil
f1 = Fiber.new do
puts 'f1-0'
f2.resume
puts 'f1-1'
f2.resume
end
f2 = Fiber.new do
puts 'f2-0'
Fiber.yield
puts 'f2-1'
Fiber.yield
end
puts 'f0-0'
f1.resume
puts 'f0-1'
# 実行結果
#
# > ruby1.9.1 transfer.rb
# f0-0
# f1-0
# f2-0
# f1-1
# f2-1
# f0-1
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment