Class: Kaisoku::Scheduler::ForkPool
- Inherits:
-
Object
- Object
- Kaisoku::Scheduler::ForkPool
- Defined in:
- lib/kaisoku/scheduler/fork_pool.rb
Instance Method Summary collapse
-
#initialize(configuration:, workers: Etc.nprocessors) ⇒ ForkPool
constructor
A new instance of ForkPool.
- #run(entities) ⇒ Object
Constructor Details
#initialize(configuration:, workers: Etc.nprocessors) ⇒ ForkPool
Returns a new instance of ForkPool.
8 9 10 11 |
# File 'lib/kaisoku/scheduler/fork_pool.rb', line 8 def initialize(configuration:, workers: Etc.nprocessors) @configuration = configuration @workers = [workers.to_i, 1].max end |
Instance Method Details
#run(entities) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/kaisoku/scheduler/fork_pool.rb', line 13 def run(entities) pending = Array(entities).dup running = {} results = [] before_fork until pending.empty? && running.empty? start_available_workers(pending, running) pid, status = Process.wait2 reader, entity, index = running.delete(pid) results << read_result(reader, entity, status) @available_indexes << index end results end |