class Bundler::ParallelWorkers::Worker - bundler-1.6.9 Documentation

# class Bundler::ParallelWorkers::Worker

### Constants

POISON

### Public Class Methods

new(size, func) click to toggle source

Creates a worker pool of specified size

@param size [Integer] Size of pool @param func [Proc] job to run in inside the worker pool

    # File lib/bundler/parallel_workers/worker.rb, line 17
    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

### Public Instance Methods

deq() click to toggle source

Retrieves results of job function being executed in worker pool

    # File lib/bundler/parallel_workers/worker.rb, line 33
    def deq
      result = @response_queue.deq
      if result.is_a?(WrappedException)
        raise result.exception
      end
      result
    end

enq(obj) click to toggle source

Enqueue a request to be executed in the worker pool

@param obj [String] mostly it is name of spec that should be downloaded

    # File lib/bundler/parallel_workers/worker.rb, line 28
    def enq(obj)
      @request_queue.enq obj
    end

stop() click to toggle source

Stop the forked workers and started threads

    # File lib/bundler/parallel_workers/worker.rb, line 42
    def stop
      stop_threads
      stop_workers
    end

### Private Instance Methods

prepare_threads(size) click to toggle source

To be overridden by child classes

    # File lib/bundler/parallel_workers/worker.rb, line 60
    def prepare_threads(size)
    end

stop_threads() click to toggle source

Stop the worker threads by sending a poison object down the request queue so as worker threads after retrieving it, shut themselves down

    # File lib/bundler/parallel_workers/worker.rb, line 50
    def stop_threads
      @threads.each do
        @request_queue.enq POISON
      end
      @threads.each do |thread|
        thread.join
      end
    end

stop_workers() click to toggle source

To be overridden by child classes

    # File lib/bundler/parallel_workers/worker.rb, line 64
    def stop_workers
    end