-
-
Save halorgium/f63abf177a96d7113ce3 to your computer and use it in GitHub Desktop.
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 'thread' | |
input = Queue.new | |
output = Queue.new | |
thread = Thread.new { | |
one = Fiber.new { | |
loop { | |
p(running: :one) | |
output << :one | |
sleep 2 | |
Fiber.yield | |
} | |
}.resume | |
two = Fiber.new { | |
loop { | |
p(running: :two) | |
output << :two | |
sleep 2 | |
Fiber.yield | |
} | |
}.resume | |
while fiber = input.pop | |
{one: one, two: two}.resume | |
end | |
} | |
input << :one | |
output.pop | |
puts "backtrace running one" | |
puts thread.backtrace | |
input << :two | |
output.pop | |
puts "backtrace running two" | |
puts thread.backtrace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment