Class: CleoQualityReview::ConcurrentExecutor
- Inherits:
-
Object
- Object
- CleoQualityReview::ConcurrentExecutor
- Defined in:
- lib/cleo_quality_review/concurrent_executor.rb
Overview
Runs independent, blocking work items across a bounded pool of threads.
The pool is sized to the available processor count by default, so it naturally expands or contracts with the host. When there are more work items than workers, the surplus waits on an internal queue and is picked up as workers free up. Results are returned in the same order as the input items.
Suited to I/O-bound work such as shelling out to external tools: while a worker thread blocks on a subprocess, Ruby releases the GIL so other workers make real progress.
Instance Method Summary collapse
-
#initialize(max_workers: nil) ⇒ ConcurrentExecutor
constructor
A new instance of ConcurrentExecutor.
-
#map(items) {|item| ... } ⇒ Array
Map over
itemsconcurrently, preserving input order.
Constructor Details
#initialize(max_workers: nil) ⇒ ConcurrentExecutor
Returns a new instance of ConcurrentExecutor.
21 22 23 24 25 26 27 |
# File 'lib/cleo_quality_review/concurrent_executor.rb', line 21 def initialize(max_workers: nil) @max_workers = if max_workers Configuration.max_concurrency_limit(max_workers) else Configuration.max_concurrency end end |
Instance Method Details
#map(items) {|item| ... } ⇒ Array
Map over items concurrently, preserving input order.
34 35 36 37 38 39 |
# File 'lib/cleo_quality_review/concurrent_executor.rb', line 34 def map(items, &block) return [] if items.empty? return items.map(&block) if serial?(items.size) process(items, &block) end |