Class: Dynflow::Future::CountDownLatch
- Inherits:
-
Object
- Object
- Dynflow::Future::CountDownLatch
- Defined in:
- lib/dynflow/future.rb
Overview
‘#future` will become resolved to `true` when “#countdown!“ is called `count` times
Instance Attribute Summary collapse
-
#future ⇒ Object
readonly
Returns the value of attribute future.
Instance Method Summary collapse
- #count ⇒ Object
- #countdown! ⇒ Object
-
#initialize(count, future = Future.new) ⇒ CountDownLatch
constructor
A new instance of CountDownLatch.
Constructor Details
#initialize(count, future = Future.new) ⇒ CountDownLatch
Returns a new instance of CountDownLatch.
12 13 14 15 16 17 |
# File 'lib/dynflow/future.rb', line 12 def initialize(count, future = Future.new) raise ArgumentError if count < 0 @count = count @lock = Mutex.new @future = future end |
Instance Attribute Details
#future ⇒ Object (readonly)
Returns the value of attribute future.
10 11 12 |
# File 'lib/dynflow/future.rb', line 10 def future @future end |
Instance Method Details
#count ⇒ Object
26 27 28 |
# File 'lib/dynflow/future.rb', line 26 def count @lock.synchronize { @count } end |
#countdown! ⇒ Object
19 20 21 22 23 24 |
# File 'lib/dynflow/future.rb', line 19 def countdown! @lock.synchronize do @count -= 1 if @count > 0 @future.resolve true if @count == 0 && !@future.ready? end end |