Sha256: a95d4f035b8c9148db842c4b67f34f7d51ac61ee6775962f02048ed75994715c

Contents?: true

Size: 662 Bytes

Versions: 1

Compression:

Stored size: 662 Bytes

Contents

module Stages
  class Stage
    attr_accessor :source
    
    def initialize(&block)
      @block = block
      @fiber_delegate = Fiber.new do
        process
        die
      end
    end
    
    def run
        @fiber_delegate.resume    
    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.run
    end
    
    def output(value)
      Fiber.yield value
    end
      
    def |(other=nil)
      other.source = self
      other
    end
  end  
end 
 

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stages-0.0.1 lib/stage_base.rb