Sha256: 4699480f889ffbe561610cba3619bd194e4e8f90894bd5d5651a54488aec3ddc

Contents?: true

Size: 488 Bytes

Versions: 132

Compression:

Stored size: 488 Bytes

Contents

require 'thread'
require 'monitor'

module ActiveSupport
  module Concurrency
    class Latch
      def initialize(count = 1)
        @count = count
        @lock = Monitor.new
        @cv = @lock.new_cond
      end

      def release
        @lock.synchronize do
          @count -= 1 if @count > 0
          @cv.broadcast if @count.zero?
        end
      end

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

Version data entries

132 entries across 127 versions & 13 rubygems

Version Path
activesupport-4.1.15 lib/active_support/concurrency/latch.rb
activesupport-4.2.6 lib/active_support/concurrency/latch.rb
activesupport-4.1.15.rc1 lib/active_support/concurrency/latch.rb
activesupport-4.2.6.rc1 lib/active_support/concurrency/latch.rb
activesupport-4.1.14.2 lib/active_support/concurrency/latch.rb
activesupport-4.2.5.2 lib/active_support/concurrency/latch.rb
activejob-lock-0.0.2 rails/activesupport/lib/active_support/concurrency/latch.rb
activesupport-4.2.5.1 lib/active_support/concurrency/latch.rb
activesupport-4.1.14.1 lib/active_support/concurrency/latch.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/activesupport-4.2.4/lib/active_support/concurrency/latch.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/activesupport-4.1.13/lib/active_support/concurrency/latch.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/activesupport-4.2.4/lib/active_support/concurrency/latch.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/activesupport-4.1.13/lib/active_support/concurrency/latch.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/concurrency/latch.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/concurrency/latch.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/activesupport-4.2.4/lib/active_support/concurrency/latch.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/activesupport-4.1.13/lib/active_support/concurrency/latch.rb
activesupport-4.1.14 lib/active_support/concurrency/latch.rb
activesupport-4.2.5 lib/active_support/concurrency/latch.rb
activesupport-4.2.5.rc2 lib/active_support/concurrency/latch.rb