Class: PeerCommander::ParallelExecutor
- Inherits:
-
Object
- Object
- PeerCommander::ParallelExecutor
- Defined in:
- lib/peer_commander/parallel_executor.rb
Overview
Executes a given set of commands with a specified parallelism
Constant Summary collapse
- SLEEP_DURATION =
0.2
Instance Method Summary collapse
- #execute(commands, parallelism) ⇒ Object
-
#initialize ⇒ ParallelExecutor
constructor
A new instance of ParallelExecutor.
Constructor Details
#initialize ⇒ ParallelExecutor
Returns a new instance of ParallelExecutor.
8 9 10 11 |
# File 'lib/peer_commander/parallel_executor.rb', line 8 def initialize @futures = [] @command_results = [] end |
Instance Method Details
#execute(commands, parallelism) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/peer_commander/parallel_executor.rb', line 13 def execute(commands, parallelism) raise ArgumentError, "Parallelism must be at least 1" if parallelism < 1 @parallelism = parallelism commands.each do |command| wait_for_slot if all_slots_filled? @futures << Concurrent::Future.execute { command.execute } end wait_for_all command_results end |