Class: Omnizip::Parallel::Engine
- Inherits:
-
Object
- Object
- Omnizip::Parallel::Engine
- Defined in:
- lib/omnizip/parallel/engine.rb
Overview
Engine owns the Fractor worker-pool dance: build the pool, submit a batch of work, run it to completion, return successful and failed results. Callers (ParallelCompressor, ParallelExtractor, future operations) supply the worker class and the work items; Engine handles the threading.
This is the deep module behind the parallel API: the threading shape is identical across every consumer, so it lives here once. Domain-specific concerns (which file to read, which archive to open, what stats to track) stay with the caller.
Instance Method Summary collapse
-
#initialize(worker_class:, threads:) ⇒ Engine
constructor
A new instance of Engine.
-
#run(work_items) {|result| ... } ⇒ Array<Fractor::WorkResult>
Run
work_itemsthrough the pool and yield each successfulFractor::WorkResultto the caller-supplied block.
Constructor Details
#initialize(worker_class:, threads:) ⇒ Engine
Returns a new instance of Engine.
21 22 23 24 |
# File 'lib/omnizip/parallel/engine.rb', line 21 def initialize(worker_class:, threads:) @worker_class = worker_class @threads = threads end |
Instance Method Details
#run(work_items) {|result| ... } ⇒ Array<Fractor::WorkResult>
Run work_items through the pool and yield each successful
Fractor::WorkResult to the caller-supplied block.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/omnizip/parallel/engine.rb', line 33 def run(work_items) pool = Fractor::WorkerPool.new( worker_class: @worker_class, num_workers: @threads, continuous: false, ) pool.start pool.submit_batch(work_items) pool.run pool.successful_results.each { |r| yield r if block_given? } pool.failed_results end |