Sha256: d0de0c129c5c6421262ae05ac699b818bf1f94b8bcf326657eca22ae737eaf32

Contents?: true

Size: 430 Bytes

Versions: 1

Compression:

Stored size: 430 Bytes

Contents

require "team_effort/version"

module TeamEffort
  def self.work(enumerable, max_process_count = 4)
    pids = []

    enumerable.each do |args|
      if pids.size == max_process_count
        finished_pid = Process.wait
        pids.delete finished_pid
      end

      pids << fork do
        yield args
      end
    end

    while !pids.empty?
      finished_pid = Process.wait
      pids.delete finished_pid
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
team_effort-0.0.2 lib/team_effort.rb