Class: ActiveSupport::Concurrency::Latch
- Defined in:
- activesupport/lib/active_support/concurrency/latch.rb
Instance Method Summary collapse
- #await ⇒ Object
-
#initialize(count = 1) ⇒ Latch
constructor
A new instance of Latch.
- #release ⇒ Object
Constructor Details
#initialize(count = 1) ⇒ Latch
Returns a new instance of Latch.
7 8 9 10 11 |
# File 'activesupport/lib/active_support/concurrency/latch.rb', line 7 def initialize(count = 1) @count = count @lock = Monitor.new @cv = @lock.new_cond end |
Instance Method Details
#await ⇒ Object
20 21 22 23 24 |
# File 'activesupport/lib/active_support/concurrency/latch.rb', line 20 def await @lock.synchronize do @cv.wait_while { @count > 0 } end end |
#release ⇒ Object
13 14 15 16 17 18 |
# File 'activesupport/lib/active_support/concurrency/latch.rb', line 13 def release @lock.synchronize do @count -= 1 if @count > 0 @cv.broadcast if @count.zero? end end |