Sha256: 1fefed13da88296a7eac664f50a67353fdfc029b3af8296041789911c41f19a8
Contents?: true
Size: 1.22 KB
Versions: 5
Compression:
Stored size: 1.22 KB
Contents
module Stages class Stage attr_accessor :source def initialize(&block) @block = block initialize_loop end def initialize_loop @fiber_delegate = Fiber.new do process die end end def run @fiber_delegate.resume end #seperate from reset! for restrict/resume purposes. def reset initialize_loop @source.reset if @source end def reset! initialize_loop @source.reset! if @source end def die loop do output nil end end def process while value = input handle_value value end end def handle_value(value) output value end def input source.nil? ? nil : source.run end def output(value) Fiber.yield value end def |(other) other.root_source.source = self other end def root_source source.nil? ? self : source.root_source end def drop_leftmost! if @source.end? @source = nil else @source.drop_leftmost! end end def end? @source.nil? end def length if source source.length + 1 else 1 end end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
stages-0.3.2 | lib/stage_base.rb |
stages-0.3.1 | lib/stage_base.rb |
stages-0.3.0 | lib/stage_base.rb |
stages-0.2.10 | lib/stage_base.rb |
stages-0.2.9 | lib/stage_base.rb |