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

def initialize(size, name, func)
  @name = name
  @request_queue = Queue.new
  @response_queue = Queue.new
  @func = func
  @size = size
  @threads = nil
  SharedHelpers.trap("INT") { abort_threads }
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



41
42
43
44
45
# File 'lib/bundler/worker.rb', line 41

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

#enq(obj) ⇒ Object

Enqueue a request to be executed in the worker pool

Parameters:

  • obj (String)

    mostly it is name of spec that should be downloaded



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

def enq(obj)
  create_threads unless @threads
  @request_queue.enq obj
end

#stopObject



47
48
49
# File 'lib/bundler/worker.rb', line 47

def stop
  stop_threads
end