123456789_123456789_123456789_123456789_123456789_

Class: ActiveSupport::Concurrency::Latch

Relationships & Source Files
Inherits: Object
Defined in: activesupport/lib/active_support/concurrency/latch.rb

Class Method Summary

Instance Method Summary

Constructor Details

.new(count = 1) ⇒ Latch

[ GitHub ]

  
# 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

[ GitHub ]

  
# File 'activesupport/lib/active_support/concurrency/latch.rb', line 20

def await
  @lock.synchronize do
    @cv.wait_while { @count > 0 }
  end
end

#release

[ GitHub ]

  
# 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