Class: Citrus::Utils::CountDownLatch
- Inherits:
-
Object
- Object
- Citrus::Utils::CountDownLatch
- Defined in:
- lib/citrus/util/countdown_latch.rb
Overview
CountDownLatch
Instance Method Summary collapse
-
#done ⇒ Object
Called when a task finish count down.
-
#initialize(count, args = {}, &block) ⇒ CountDownLatch
constructor
Create a count down latch.
Constructor Details
#initialize(count, args = {}, &block) ⇒ CountDownLatch
Create a count down latch
18 19 20 21 22 23 24 25 26 |
# File 'lib/citrus/util/countdown_latch.rb', line 18 def initialize count, args={}, &block @count = count @block = block if args[:timeout] @timer = EM::Timer.new(args[:timeout]) { @block.respond_to? :call and @block.call true } end end |
Instance Method Details
#done ⇒ Object
Called when a task finish count down
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/citrus/util/countdown_latch.rb', line 29 def done unless @count > 0 throw Exception.new 'illegal state' end @count -= 1 if @count == 0 @timer.cancel if @timer @block.respond_to? :call and @block.call end end |