Skip to content

Instantly share code, notes, and snippets.

@cheald
Last active August 29, 2015 13:55
Show Gist options
  • Save cheald/8699906 to your computer and use it in GitHub Desktop.
Save cheald/8699906 to your computer and use it in GitHub Desktop.
f = Fiber.new {
begin
Timeout.timeout(1) {
p Fiber.yield
}
rescue Exception => e
puts e.inspect
p Fiber.yield
end
}
f.resume "resume 1"
sleep 1.5
f.resume "resume 2"
2.0.0-p247 :001 > require 'timeout'
=> true
2.0.0-p247 :002 > require 'fiber'
=> true
2.0.0-p247 :003 > f = Fiber.new {
2.0.0-p247 :004 > begin
2.0.0-p247 :005 > Timeout.timeout(1) {
2.0.0-p247 :006 > p Fiber.yield("y1")
2.0.0-p247 :007?> }
2.0.0-p247 :008?> rescue Exception => e
2.0.0-p247 :009?> puts e.inspect
2.0.0-p247 :010?> end
2.0.0-p247 :011?> p Fiber.yield("y2")
2.0.0-p247 :012?> }
=> #<Fiber:0x00000003daf090>
2.0.0-p247 :013 > p f.resume "resume 1"
"y1"
=> "y1"
2.0.0-p247 :014 > sleep 1.5
#<Class:0x00000003db2d08>: execution expired
from (irb):14:in `sleep'
from (irb):14
from /usr/local/rvm/rubies/ruby-2.0.0-p247/bin/irb:13:in `<main>'
2.0.0-p247 :015 > p f.resume "resume 2"
"resume 2"
"y2"
=> "y2"
2.0.0-p247 :016 > f.resume
nil
=> nil
2.0.0-p247 :017 > f.resume
FiberError: dead fiber called
from (irb):17:in `resume'
from (irb):17
from /usr/local/rvm/rubies/ruby-2.0.0-p247/bin/irb:13:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment