Class: IOPromise::ExecutorPool::Batch

Inherits:
Base
  • Object
show all
Defined in:
lib/iopromise/executor_pool/batch.rb

Direct Known Subclasses

Deferred::DeferredExecutorPool

Instance Attribute Summary

Attributes inherited from Base

#select_timeout

Instance Method Summary collapse

Methods inherited from Base

#begin_executing, #execute_continue, for, #promise_cancelled, #promise_fulfilled, #promise_rejected, #register, #sync

Constructor Details

#initializeBatch

Returns a new instance of Batch.



6
7
8
9
10
# File 'lib/iopromise/executor_pool/batch.rb', line 6

def initialize(*)
  super
    
  @current_batch = []
end

Instance Method Details

#next_batchObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/iopromise/executor_pool/batch.rb', line 12

def next_batch
  # ensure that all current items are fully completed
  @current_batch.each do |promise|
    promise.wait
  end
  
  # every pending operation becomes part of the current batch
  # we don't include promises with a source set, because that
  # indicates that they depend on another promise now.
  @current_batch = @pending.select { |p| p.pending? && p.source.nil? }
end