Class: Bundler::Worker
- Inherits:
-
Object
- Object
- Bundler::Worker
- Defined in:
- lib/bundler/worker.rb
Defined Under Namespace
Classes: WrappedException
Constant Summary collapse
- POISON =
Object.new
Instance Method Summary collapse
-
#deq ⇒ Object
Retrieves results of job function being executed in worker pool.
-
#enq(obj) ⇒ Object
Enqueue a request to be executed in the worker pool.
-
#initialize(size, func) ⇒ Worker
constructor
Creates a worker pool of specified size.
- #stop ⇒ Object
Constructor Details
#initialize(size, func) ⇒ Worker
Creates a worker pool of specified size
18 19 20 21 22 23 24 |
# File 'lib/bundler/worker.rb', line 18 def initialize(size, func) @request_queue = Queue.new @response_queue = Queue.new @func = func @threads = size.times.map { |i| Thread.start { process_queue(i) } } trap("INT") { abort_threads } end |
Instance Method Details
#deq ⇒ Object
Retrieves results of job function being executed in worker pool
34 35 36 37 38 |
# File 'lib/bundler/worker.rb', line 34 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
29 30 31 |
# File 'lib/bundler/worker.rb', line 29 def enq(obj) @request_queue.enq obj end |
#stop ⇒ Object
40 41 42 |
# File 'lib/bundler/worker.rb', line 40 def stop stop_threads end |