Class: Pull::Collect
- Inherits:
-
Object
- Object
- Pull::Collect
- Defined in:
- lib/pull/sink/collect.rb
Constant Summary collapse
- DEFAULT_DONE_CALLBACK =
-> () { puts "DONE" }
Instance Method Summary collapse
- #call(read, done = DEFAULT_DONE_CALLBACK) ⇒ Object
-
#initialize(&block) ⇒ Collect
constructor
A new instance of Collect.
Constructor Details
#initialize(&block) ⇒ Collect
9 10 11 12 |
# File 'lib/pull/sink/collect.rb', line 9 def initialize(&block) @block = block @collection = [] end |
Instance Method Details
#call(read, done = DEFAULT_DONE_CALLBACK) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/pull/sink/collect.rb', line 14 def call(read, done = DEFAULT_DONE_CALLBACK) raise TypeError unless read.respond_to?(:call) drained = Pull::Drain.new do |value| @collection << value end drained.(read) block.call(@collection) end |