Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save athom/2035185 to your computer and use it in GitHub Desktop.
Save athom/2035185 to your computer and use it in GitHub Desktop.
Simple example of concurrency in Ruby with Fiber.
require "fiber"
f1 = Fiber.new { |f2| f2.resume Fiber.current;loop{puts "A"; f2.transfer} }
f2 = Fiber.new { |f1| f1.transfer; loop{puts "B"; f1.transfer} }
f1.resume f2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment