Class: PDK::CLI::ParallelExecGroup
- Defined in:
- lib/pdk/cli/exec_group.rb
Overview
Executes registered blocks in parallel using Ruby threads
Instance Method Summary collapse
- #exit_code ⇒ Object
-
#initialize(message, opts = {}) ⇒ ParallelExecGroup
constructor
A new instance of ParallelExecGroup.
- #register(&block) ⇒ Object
Methods inherited from ExecGroup
Constructor Details
#initialize(message, opts = {}) ⇒ ParallelExecGroup
Returns a new instance of ParallelExecGroup.
77 78 79 80 81 |
# File 'lib/pdk/cli/exec_group.rb', line 77 def initialize(, opts = {}) super(, opts) @threads = [] @exit_codes = [] end |
Instance Method Details
#exit_code ⇒ Object
95 96 97 98 99 100 |
# File 'lib/pdk/cli/exec_group.rb', line 95 def exit_code @threads.each(&:join) return 0 if @exit_codes.empty? @exit_codes.max end |
#register(&block) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/pdk/cli/exec_group.rb', line 83 def register(&block) super(&block) # TODO: This executes the thread immediately, whereas the SerialExecGroup executes only when exit_code # is called. Need to change this so it uses a kind of ThreadPool to limit to number on concurrent jobs # and only starts on the call to exit_code # e.g. max_threads = No. of CPUs @threads << Thread.new do @exit_codes << yield end end |