Skip to content

Instantly share code, notes, and snippets.

@mattn
Last active December 19, 2015 01:19
Show Gist options
  • Save mattn/5874949 to your computer and use it in GitHub Desktop.
Save mattn/5874949 to your computer and use it in GitHub Desktop.
class Fiber
include Enumerable
def each
begin
loop { yield self.resume }
rescue FiberError
end
end
end
puts Fiber.new {
Fiber.yield 3
Fiber.yield 2
Fiber.yield 1
Fiber.yield 0
}.to_enum.to_a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment