module InParallel

Constants

VERSION

Public Instance Methods

parallel_default_timeout() click to toggle source

Gets how many seconds to wait before timing out a forked child process and raising an exception

# File lib/in_parallel.rb, line 342
def parallel_default_timeout
  InParallelExecutor.parallel_default_timeout
end
parallel_default_timeout=(value) click to toggle source

Sets how many seconds to wait before timing out a forked child process and raising an exception @param [Int] value Time in seconds to wait before timing out and raising an exception

# File lib/in_parallel.rb, line 348
def parallel_default_timeout=(value)
  InParallelExecutor.parallel_default_timeout = value
end
parallel_signal_interval() click to toggle source

Gets how many seconds to wait between logging a 'Waiting for child processes.'

# File lib/in_parallel.rb, line 331
def parallel_signal_interval
  InParallelExecutor.parallel_signal_interval
end
parallel_signal_interval=(value) click to toggle source

Sets how many seconds to wait between logging a 'Waiting for child processes.' @param [Int] value Time in seconds to wait before logging 'Waiting for child processes.'

# File lib/in_parallel.rb, line 337
def parallel_signal_interval=(value)
  InParallelExecutor.parallel_signal_interval = value
end
run_in_background(ignore_result = true, &block) click to toggle source

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 do
  @result_1 = method1
  @result_2 = method2
end

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) do
  @result_1 = method1
  @result_2 = method2
end
# 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” @param [Boolean] ignore_result True if you do not care about the STDOUT or return value of the methods executing in the background @param [Block] block This method will yield to a block of code passed by the caller @return [Array<Result>, Result] the return values of each method within the block

# File lib/in_parallel.rb, line 390
def run_in_background(ignore_result = true, &block)
  InParallelExecutor.run_in_background(ignore_result, &block)
end
run_in_parallel(timeout=nil, kill_all_on_error = false, &block) click to toggle source

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 do
  @result_1 = method1
  @result_2 = method2
end

NOTE - Only instance variables can be assigned the return values of the methods within the block. Local variables will not be assigned any values. @param [Int] timeout Time in seconds to wait before giving up on a child process @param [Boolean] kill_all_on_error Whether to wait for all processes to complete, or fail immediately - killing all other forked processes - when one process errors. @param [Block] block This method will yield to a block of code passed by the caller @return [Array<Result>, Result] the return values of each method within the block

# File lib/in_parallel.rb, line 364
def run_in_parallel(timeout=nil, kill_all_on_error = false, &block)
  timeout ||= InParallelExecutor.parallel_default_timeout
  InParallelExecutor.run_in_parallel(timeout, kill_all_on_error, &block)
end
wait_for_processes(timeout=nil, kill_all_on_error = false) click to toggle source

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 @param [Int] timeout Time in seconds to wait before giving up on a child process @param [Boolean] kill_all_on_error Whether to wait for all processes to complete, or fail immediately - killing all other forked processes - when one process errors. @return [Array<Result>, Result] the temporary return values of each method within the block

# File lib/in_parallel.rb, line 398
def wait_for_processes(timeout=nil, kill_all_on_error = false)
  timeout ||= InParallelExecutor.parallel_default_timeout
  InParallelExecutor.wait_for_processes(nil, nil, timeout, kill_all_on_error)
end