Module: Pod::PodGenerate::Parallel::ThreadPool

Defined in:
lib/cocoapods-podgenerate/parallel/thread_pool.rb

Class Method Summary collapse

Class Method Details

.create(size: nil) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/cocoapods-podgenerate/parallel/thread_pool.rb', line 26

def create(size: nil)
  pool_size = size || default_size
  # Return an array of available threads - caller manages them
  Array.new(pool_size) { Thread.new { sleep } }.each(&:exit)
  # We use a simpler approach - caller creates threads directly
  nil
end

.default_sizeObject



12
13
14
15
16
# File 'lib/cocoapods-podgenerate/parallel/thread_pool.rb', line 12

def default_size
  @default_size ||= [Etc.nprocessors - 1, 2].max
rescue NameError
  @default_size ||= 4
end

.with_pool(size: nil, &block) ⇒ Object

Create and yield a thread pool, then shut it down.



19
20
21
22
23
24
# File 'lib/cocoapods-podgenerate/parallel/thread_pool.rb', line 19

def with_pool(size: nil, &block)
  pool = create(size: size)
  yield pool
ensure
  pool&.each(&:kill)
end