Skip to content

Instantly share code, notes, and snippets.

@fsword
Created March 13, 2012 12:39
Show Gist options
  • Save fsword/2028524 to your computer and use it in GitHub Desktop.
Save fsword/2028524 to your computer and use it in GitHub Desktop.
fiber transfer 例子
require 'fiber'
x = nil
f1 = nil
f1 = Fiber.new do |f|
1000.times do
p 'f1'
sleep 0.1
f.transfer Fiber.current
end
end
f2 = Fiber.new do |f|
1000.times do
p 'f2'
sleep 0.1
f.transfer Fiber.current
end
end
x = true
f1.resume f2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment