Sha256: fa0d95285a9c7f9501bb49e9c5d4dfb3300765a1881139c92c148df0aa657496

Contents?: true

Size: 672 Bytes

Versions: 1

Compression:

Stored size: 672 Bytes

Contents

require_relative "team_effort/version"

module TeamEffort
  def self.work(enumerable, max_process_count = 4, progress_proc: nil)
    pids = []
    max_count = enumerable.count
    completed_count = 0

    enumerable.each do |args|
      while pids.size == max_process_count
        finished_pid = Process.wait
        pids.delete finished_pid
        progress_proc.call(completed_count += 1, max_count) if progress_proc
      end

      pids << fork do
        yield args
      end
    end

    while !pids.empty?
      finished_pid = Process.wait
      pids.delete finished_pid
      progress_proc.call(completed_count += 1, max_count) if progress_proc
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
team_effort-0.0.9 lib/team_effort.rb