Module: InParallel
- Defined in:
- lib/in_parallel.rb
Defined Under Namespace
Classes: InParallelExecutor
Instance Method Summary collapse
-
#run_in_background(ignore_result = true, &block) ⇒ Array<Result>, Result
Forks a process for each method within a block and returns immediately Example 1 - Will fork a process in the background to execute each method and return immediately: Parallel.run_in_background { @result_1 = method1 @result_2 = method2 }.
-
#run_in_parallel(&block) ⇒ Array<Result>, Result
Executes each method within a block in a different process Example - Will spawn a process in the background to execute each method Parallel.run_in_parallel { @result_1 = method1 @result_2 = method2 } NOTE - Only instance variables can be assigned the return values of the methods within the block.
-
#wait_for_processes ⇒ Array<Result>, Result
Waits for all processes started by run_in_background to complete execution, then prints STDOUT and assigns return values to instance variables.
Instance Method Details
#run_in_background(ignore_result = true, &block) ⇒ Array<Result>, Result
Forks a process for each method within a block and returns immediately Example 1 - Will fork a process in the background to execute each method and return immediately: Parallel.run_in_background
@result_1 = method1
@result_2 = method2
Example 2 - Will fork a process in the background to execute each method, return immediately, then later wait for the process to complete, printing it’s STDOUT and assigning return values to instance variables: Parallel.run_in_background(false)
@result_1 = method1
@result_2 = method2
# Do something else here before waiting for the process to complete
wait_for_processes NOTE: must call wait_for_processes to allow instance variables within the block to be set, otherwise results will evaluate to “unresolved_parallel_result_X”
291 292 293 |
# File 'lib/in_parallel.rb', line 291 def run_in_background(ignore_result = true, &block) InParallelExecutor.run_in_background(ignore_result, &block) end |
#run_in_parallel(&block) ⇒ Array<Result>, Result
Executes each method within a block in a different process Example - Will spawn a process in the background to execute each method Parallel.run_in_parallel
@result_1 = method1
@result_2 = method2
NOTE - Only instance variables can be assigned the return values of the methods within the block. Local variables will not be assigned any values.
266 267 268 |
# File 'lib/in_parallel.rb', line 266 def run_in_parallel(&block) InParallelExecutor.run_in_parallel(&block) end |
#wait_for_processes ⇒ Array<Result>, Result
Waits for all processes started by run_in_background to complete execution, then prints STDOUT and assigns return values to instance variables. See :run_in_background
298 299 300 |
# File 'lib/in_parallel.rb', line 298 def wait_for_processes InParallelExecutor.wait_for_processes end |