Module: Pod::PodGenerate::Parallel::BatchProcessor
- Defined in:
- lib/cocoapods-podgenerate/parallel/batch_processor.rb
Class Method Summary collapse
-
.process(items, pool:, batch_size: nil) {|item| ... } ⇒ Array
Process items in batches using a thread pool.
Class Method Details
.process(items, pool:, batch_size: nil) {|item| ... } ⇒ Array
Process items in batches using a thread pool.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cocoapods-podgenerate/parallel/batch_processor.rb', line 19 def self.process(items, pool:, batch_size: nil, &block) return [] if items.empty? results = Array.new(items.size) mutex = Mutex.new count = items.size completed = 0 items.each_with_index do |item, idx| pool.post do begin result = block.call(item) mutex.synchronize { results[idx] = result } rescue StandardError => e mutex.synchronize do Pod::UI.warn "[cocoapods-podgenerate] BatchProcessor error on item #{idx}: #{e.}" end ensure mutex.synchronize do completed += 1 end end end end # Wait for all tasks to complete pool.wait_for_termination results end |