Module: Pod::PodGenerate::Parallel::BatchProcessor
- Defined in:
- lib/cocoapods-podgenerate/parallel/batch_processor.rb
Class Method Summary collapse
-
.process(items, pool:) {|item| ... } ⇒ Array
在线程池中并行处理项目,保持结果的输入顺序.
Class Method Details
.process(items, pool:) {|item| ... } ⇒ Array
在线程池中并行处理项目,保持结果的输入顺序
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/cocoapods-podgenerate/parallel/batch_processor.rb', line 26 def self.process(items, pool:, &block) return [] if items.empty? results = Array.new(items.size) mutex = Mutex.new items.each_with_index do |item, idx| pool.post do result = block.call(item) mutex.synchronize { results[idx] = result } rescue StandardError => e Pod::UI.warn "[cocoapods-podgenerate] BatchProcessor error on item #{idx}: #{e.}" end end # v0.1.4: 带超时的等待 pool.shutdown unless pool.wait_for_termination(Pod::PodGenerate::Parallel::ThreadPool::DEFAULT_TIMEOUT) Pod::UI.warn '[cocoapods-podgenerate] BatchProcessor timed out after 120s' pool.kill end results end |