class Bundler::ParallelWorkers::UnixWorker

def prepare_workers(size, func)

Parameters:
  • func (Proc) -- Job that should be executed in the worker
  • size (Integer) -- Size of worker pool
def prepare_workers(size, func)
  @workers = size.times.map do |num|
    child_read, parent_write = IO.pipe
    parent_read, child_write = IO.pipe
    pid = Process.fork do
      begin
        parent_read.close
        parent_write.close
        while !child_read.eof?
          obj = Marshal.load child_read
          Marshal.dump func.call(obj, num), child_write
        end
      rescue Exception => e
        begin
          Marshal.dump WrappedException.new(e), child_write
        rescue Errno::EPIPE
          nil
        end
      ensure
        child_read.close
        child_write.close
      end
    end
    child_read.close
    child_write.close
    JobHandler.new pid, parent_read, parent_write
  end
end