Created
March 13, 2012 12:39
-
-
Save fsword/2028524 to your computer and use it in GitHub Desktop.
fiber transfer 例子
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' | |
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