Module: Affect::Fiber
Defined Under Namespace
Classes: Context, Escape, Intent
Instance Method Summary collapse
- #capture(*args, &block) ⇒ Object
- #escape(value = nil, &block) ⇒ Object
- #method_missing(*args) ⇒ Object
- #perform(*args) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
61 62 63 |
# File 'lib/affect/fiber.rb', line 61 def method_missing(*args) perform(*args) end |
Instance Method Details
#capture(*args, &block) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/affect/fiber.rb', line 28 def capture(*args, &block) block, handler = case args.size when 1 then block ? [block, args.first] : [args.first, nil] when 2 then args else [block, nil] end f = Fiber.new(&block) v = f.resume loop do break v unless f.alive? && v.is_a?(Intent) if v.is_a?(Escape) break v.() else v = f.resume(handler.(*v.args)) end end end |