Skip to content

Instantly share code, notes, and snippets.

@DAddYE
Created November 26, 2012 19:55
Show Gist options
  • Save DAddYE/4150248 to your computer and use it in GitHub Desktop.
Save DAddYE/4150248 to your computer and use it in GitHub Desktop.
Simple example of concurrency in Ruby with Fiber.
require "fiber"
f1 = Fiber.new do |f2|
while true
puts "A"
sleep 2
f2.transfer
end
end
f2 = Fiber.new do |f1|
f1.resume Fiber.current
while true
puts "B"
sleep 2
f1.transfer
end
end
f2.resume f1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment