class Bundler::ParallelWorkers::Worker

def deq

Retrieves results of job function being executed in worker pool
def deq
  result = @response_queue.deq
  if result.is_a?(WrappedException)
    raise result.exception
  end
  result
end

def enq(obj)

Parameters:
  • obj (String) -- mostly it is name of spec that should be downloaded
def enq(obj)
  @request_queue.enq obj
end

def initialize(size, func)

Parameters:
  • func (Proc) -- job to run in inside the worker pool
  • size (Integer) -- Size of pool
def initialize(size, func)
  @request_queue = Queue.new
  @response_queue = Queue.new
  prepare_workers size, func
  prepare_threads size
  trap("INT") { @threads.each {|i| i.exit }; stop_workers; exit 1 }
end

def prepare_threads(size)

To be overridden by child classes
def prepare_threads(size)
end

def stop

Stop the forked workers and started threads
def stop
  stop_threads
  stop_workers
end

def stop_threads

so as worker threads after retrieving it, shut themselves down
Stop the worker threads by sending a poison object down the request queue
def stop_threads
  @threads.each do
    @request_queue.enq POISON
  end
  @threads.each do |thread|
    thread.join
  end
end

def stop_workers

To be overridden by child classes
def stop_workers
end