Class: JsDuck::Util::Parallel

Inherits:
Object
  • Object
show all
Defined in:
lib/jsduck/util/parallel.rb

Overview

Wrapper around the parallel gem that falls back to simple Array#map and Array#each when :in_processes => 0 specified.

Constant Summary collapse

@@in_processes =
nil

Class Method Summary collapse

Class Method Details

.configure(opts) ⇒ Object

Configures the logger to use as many processes as set in command line options. When in Windows, turns the parallel processing off by default.



15
16
17
18
# File 'lib/jsduck/util/parallel.rb', line 15

def self.configure(opts)
  @@in_processes = 0 if Util::OS::windows?
  @@in_processes = opts.processes if opts.processes
end

.each(arr, &block) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/jsduck/util/parallel.rb', line 20

def self.each(arr, &block)
  if @@in_processes == 0
    arr.each &block
  else
    ::Parallel.each(arr, {:in_processes => @@in_processes}, &block)
  end
end

.map(arr, &block) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/jsduck/util/parallel.rb', line 28

def self.map(arr, &block)
  if @@in_processes == 0
    arr.map &block
  else
    ::Parallel.map(arr, {:in_processes => @@in_processes}, &block)
  end
end