Class: Bundler::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/worker.rb

Defined Under Namespace

Classes: WrappedException

Constant Summary collapse

POISON =
Object.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(size, name, func) ⇒ Worker

Creates a worker pool of specified size

Parameters:

  • size (Integer)

    Size of pool

  • name (String)

    name the name of the worker

  • func (Proc)

    job to run in inside the worker pool



22
23
24
25
26
27
28
29
30
31
# File 'lib/bundler/worker.rb', line 22

def initialize(size, name, func)
  @name = name
  @request_queue = Thread::Queue.new
  @request_queue_with_priority = Thread::Queue.new
  @response_queue = Thread::Queue.new
  @func = func
  @size = size
  @threads = nil
  @previous_interrupt_handler = nil
end

Instance Attribute Details

#nameString (readonly)

Returns the name of the worker.

Returns:

  • (String)

    the name of the worker



15
16
17
# File 'lib/bundler/worker.rb', line 15

def name
  @name
end

Instance Method Details

#deqObject

Retrieves results of job function being executed in worker pool



43
44
45
46
47
# File 'lib/bundler/worker.rb', line 43

def deq
  result = @response_queue.deq
  raise result.exception if result.is_a?(WrappedException)
  result
end

#enq(obj, priority: false) ⇒ Object

Enqueue a request to be executed in the worker pool

Parameters:

  • obj (String)

    mostly it is name of spec that should be downloaded



36
37
38
39
40
# File 'lib/bundler/worker.rb', line 36

def enq(obj, priority: false)
  queue = priority ? @request_queue_with_priority : @request_queue
  create_threads unless @threads
  queue.enq obj
end

#stopObject



49
50
51
# File 'lib/bundler/worker.rb', line 49

def stop
  stop_threads
end