aboutsummaryrefslogblamecommitdiffstats
path: root/activesupport/lib/active_support/concurrency/latch.rb
blob: 53e09b685c7d3b5b3ed04d6a79bebf6f460e3587 (plain) (tree)
1
2
3
4
5
6
                                            


                    
               
                               






                                                                                                                                            
         
 


                         

               
                        



         
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