Top Level Namespace

Defined Under Namespace

Modules: Enumerable Classes: ParallelException

Instance Method Summary collapse

Instance Method Details

#parallelize(num_threads, collect_exceptions = false, &block) ⇒ Array

Execute the given block with multiple threads.

Parameters:

  • num_threads (Fixnum)

    Number of concurrent threads

  • collect_exceptions (Boolean) (defaults to: false)

    If true, waits for all threads to complete even in case of exception, and throws ParallelException at the end. If false exception is immediately thrown.

Returns:

  • (Array)

    Threads.



8
9
10
# File 'lib/parallelize.rb', line 8

def parallelize num_threads, collect_exceptions = false, &block
  num_threads.times.peach(num_threads, collect_exceptions, &block)
end