Class: Daemonic::Pool
- Inherits:
-
Object
- Object
- Daemonic::Pool
- Defined in:
- lib/daemonic/pool.rb
Defined Under Namespace
Classes: StopSignal
Constant Summary collapse
- STOP_SIGNAL =
StopSignal.new
Instance Attribute Summary collapse
-
#producer ⇒ Object
readonly
Returns the value of attribute producer.
Instance Method Summary collapse
- #enqueue(job) ⇒ Object (also: #<<)
-
#initialize(producer) ⇒ Pool
constructor
A new instance of Pool.
- #stop ⇒ Object
Constructor Details
#initialize(producer) ⇒ Pool
Returns a new instance of Pool.
18 19 20 21 22 23 24 25 26 |
# File 'lib/daemonic/pool.rb', line 18 def initialize(producer) @producer = producer @jobs = SizedQueue.new(producer.queue_size) @threads = producer.concurrency.times.map {|worker_num| Thread.new do dispatch(worker_num) end } end |
Instance Attribute Details
#producer ⇒ Object (readonly)
Returns the value of attribute producer.
16 17 18 |
# File 'lib/daemonic/pool.rb', line 16 def producer @producer end |
Instance Method Details
#enqueue(job) ⇒ Object Also known as: <<
28 29 30 31 |
# File 'lib/daemonic/pool.rb', line 28 def enqueue(job) logger.debug { "Enqueueing #{job.inspect}" } @jobs.push(job) end |
#stop ⇒ Object
34 35 36 37 38 39 |
# File 'lib/daemonic/pool.rb', line 34 def stop @threads.size.times do enqueue(STOP_SIGNAL) end @threads.each(&:join) end |