aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/concurrency/latch.rb
blob: 045beca3dc753526b2b6a1f21dda23045b862a33 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
require "concurrent/atomic/count_down_latch"

module ActiveSupport
  module Concurrency
    class Latch

      def initialize(count = 1)
        if count == 1
          ActiveSupport::Deprecation.warn("ActiveSupport::Concurrency::Latch is deprecated. Please use Concurrent::Event instead.")
        else
          ActiveSupport::Deprecation.warn("ActiveSupport::Concurrency::Latch is deprecated. Please use Concurrent::CountDownLatch instead.")
        end

        @inner = Concurrent::CountDownLatch.new(count)
      end

      def release
        @inner.count_down
      end

      def await
        @inner.wait(nil)
      end
    end
  end
end