Class: Orchestra::Performance::CollectionMovement
- Inherits:
-
Movement
- Object
- Movement
- Orchestra::Performance::CollectionMovement
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
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
|
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_collection ⇒ Object
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
|