Sha256: 81e5eac6b400cde9bedf369ccdd17218cc8e3cb4e7141dc9b565d9c2d46fbbd9

Contents?: true

Size: 695 Bytes

Versions: 3

Compression:

Stored size: 695 Bytes

Contents

require 'parallel'

module JsDuck

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

    # Sets globally the nr of processes to use.
    def self.in_processes=(n)
      @@in_processes = n
    end

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

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

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jsduck-4.0.1 lib/jsduck/parallel_wrap.rb
jsduck-4.0.0 lib/jsduck/parallel_wrap.rb
jsduck-4.0.beta2 lib/jsduck/parallel_wrap.rb