Skip to content

Instantly share code, notes, and snippets.

@scalone
Created May 29, 2014 05:02
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 scalone/23f39caf2f7e8917795e to your computer and use it in GitHub Desktop.
Save scalone/23f39caf2f7e8917795e to your computer and use it in GitHub Desktop.
fib = Fiber.new do
x, y = 0, 1
loop do
puts "before stop"
Fiber.yield y
puts "after stop"
x,y = y,x+y
end
end
#20.times { puts fib.resume }
class T
def initialize()
end
def execute
[:print, :key_read, :print].each do |m|
self.send m
end
end
def print
puts "print"
end
def key_read
@fib = Fiber.new do
key = "enter"
Fiber.yield key
end
end
end
run_time = Fiber do
T.new.execute
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment