Module: ConcurrencyHelper
- Defined in:
- lib/sapis/concurrency_helper.rb
Overview
<concurrency_helper.rb> - Part of Sav’s APIs. Copyright © 2011 Saverio Miroddi
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <www.gnu.org/licenses/>.
Defined Under Namespace
Classes: ParallelWorkersQueue
Class Method Summary collapse
Class Method Details
.with_parallel_queue(slots, options = {}) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/sapis/concurrency_helper.rb', line 79 def self.with_parallel_queue(slots, ={}) instances = [:instances] abort_on_exception = [:abort_on_exception] queue = ParallelWorkersQueue.new(slots, :abort_on_exception => abort_on_exception) semaphore = Mutex.new if instances instances.each do |instance| proc = yield(instance, semaphore) raise "The value returned is not a Proc!" unless proc.is_a?(Proc) queue.push(&proc) end else yield(queue, semaphore) end queue.join end |