Class: Marso::FiberProjection

Inherits:
Enumerate show all
Defined in:
lib/marso/toolbelt/fiberpiping.rb

Constant Summary

Constants inherited from Enumerate

Enumerate::STOP_MSG

Instance Attribute Summary

Attributes inherited from Enumerate

#process, #src

Instance Method Summary collapse

Methods inherited from Enumerate

#clone, #execute, from, #resume, #select, #select_many, #to_a, #where, #|

Constructor Details

#initialize(process, source = {}) ⇒ FiberProjection

Returns a new instance of FiberProjection.



109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/marso/toolbelt/fiberpiping.rb', line 109

def initialize(process, source={})
  @src = source
  @process = process

  @fiber_delegate = Fiber.new do
    output = nil
    while input = Fiber.yield(output)
      output = process.call(input)
    end
  end

  @fiber_delegate.resume
end

Instance Method Details

#source(other_source) ⇒ Object



123
124
125
# File 'lib/marso/toolbelt/fiberpiping.rb', line 123

def source(other_source)
  FiberProjection.new(@process, other_source)
end