Class: Bundler::ParallelWorkers::Worker
- Inherits:
-
Object
- Object
- Bundler::ParallelWorkers::Worker
- Defined in:
- lib/bundler/parallel_workers/worker.rb
Direct Known Subclasses
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
Stop the forked workers and started threads.
Constructor Details
#initialize(size, func) ⇒ Worker
Creates a worker pool of specified size
17 18 19 20 21 22 23 |
# 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 |
Instance Method Details
#deq ⇒ Object
Retrieves results of job function being executed in worker pool
33 34 35 36 37 38 39 |
# 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) ⇒ Object
Enqueue a request to be executed in the worker pool
28 29 30 |
# File 'lib/bundler/parallel_workers/worker.rb', line 28 def enq(obj) @request_queue.enq obj end |
#stop ⇒ Object
Stop the forked workers and started threads
42 43 44 45 |
# File 'lib/bundler/parallel_workers/worker.rb', line 42 def stop stop_threads stop_workers end |