Class: WorkerPool::CountdownLatch
- Inherits:
-
Object
- Object
- WorkerPool::CountdownLatch
- Defined in:
- lib/worker_pool/countdown_latch.rb
Instance Method Summary collapse
- #decrement ⇒ Object
-
#initialize(count) ⇒ CountdownLatch
constructor
A new instance of CountdownLatch.
-
#wait(_timeout) ⇒ Object
TODO: Implement timeouts.
Constructor Details
#initialize(count) ⇒ CountdownLatch
Returns a new instance of CountdownLatch.
5 6 7 |
# File 'lib/worker_pool/countdown_latch.rb', line 5 def initialize(count) @count, @mutex, @resource = count, Mutex.new, ConditionVariable.new end |
Instance Method Details
#decrement ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/worker_pool/countdown_latch.rb', line 9 def decrement @mutex.synchronize do @count -= 1 if @count <= 0 @resource.broadcast end end end |
#wait(_timeout) ⇒ Object
TODO: Implement timeouts
19 20 21 22 23 24 25 26 27 |
# File 'lib/worker_pool/countdown_latch.rb', line 19 def wait(_timeout) @mutex.synchronize do if @count > 0 @resource.wait(@mutex) else @resource.broadcast end end end |