Skip to content

Instantly share code, notes, and snippets.

@halorgium halorgium/fiber-backtrace.rb Secret
Created Apr 13, 2013

Embed
What would you like to do?
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
You can’t perform that action at this time.