class Salus::CountDownLatch

Based on code from github.com/ruby-concurrency/concurrent-ruby/

Public Class Methods

new(to=1) click to toggle source
# File lib/salus/thread/latch.rb, line 6
def initialize(to=1)
  synchronize { @count = to.to_i }
  raise ArgumentError, "cannot count down from negative integer" unless @count >= 0
end

Public Instance Methods

count() click to toggle source
# File lib/salus/thread/latch.rb, line 18
def count
  synchronize { @count }
end
count_down() click to toggle source
# File lib/salus/thread/latch.rb, line 11
def count_down
  synchronize do
    @count -= 1 if @count >  0
    broadcast   if @count == 0
  end
end
wait(timeout=nil) click to toggle source
# File lib/salus/thread/latch.rb, line 22
def wait(timeout=nil)
  synchronize do
    wait_until(timeout) { @count == 0 }
  end
end