Skip to content

Instantly share code, notes, and snippets.

@tdantas
Last active May 6, 2019 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdantas/6310407 to your computer and use it in GitHub Desktop.
Save tdantas/6310407 to your computer and use it in GitHub Desktop.
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