Class: Orchestra::Performance::CollectionMovement

Inherits:
Movement
  • Object
show all
Defined in:
lib/orchestra/performance.rb

Instance Attribute Summary

Attributes inherited from Movement

#context, #node, #performance

Instance Method Summary collapse

Methods inherited from Movement

#build_context, #initialize, perform

Constructor Details

This class inherits a constructor from Orchestra::Performance::Movement

Instance Method Details

#enqueue_job(element, index) ⇒ Object



106
107
108
109
110
111
# File 'lib/orchestra/performance.rb', line 106

def enqueue_job element, index
  performance.thread_pool.enqueue do
    result = context.perform element
    yield [result, index]
  end
end

#enqueue_jobs(batch, &block) ⇒ Object



100
101
102
103
104
# File 'lib/orchestra/performance.rb', line 100

def enqueue_jobs batch, &block
  batch.map.with_index do |element, index|
    enqueue_job element, index, &block
  end
end

#performObject



93
94
95
96
97
98
# File 'lib/orchestra/performance.rb', line 93

def perform
  batch, output = prepare_collection
  jobs = enqueue_jobs batch do |result, index| output[index] = result end
  jobs.each &:wait
  output
end

#prepare_collectionObject



113
114
115
116
117
# File 'lib/orchestra/performance.rb', line 113

def prepare_collection
  batch = context.fetch_collection
  output = [nil] * batch.size
  [batch, output]
end