Skip to content

Instantly share code, notes, and snippets.

@tdantas
Last active May 6, 2019
Embed
What would you like to do?
Fiber Ruby
$ ruby poc_fiber.rb
"hello"
"world"
require 'thread'
q = Queue.new
thr = Thread.new do
f1 = Fiber.new do
Fiber.yield "hello"
end
f2 = Fiber.new do
Fiber.yield "world"
end
q.push(f1)
q.push(f2)
q.push(q)
while (f = q.pop) != q
p f.resume
end
end
thr.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment