Sha256: 5c5b6d5825a27b2acfcee04417df23bc62baf127534c175ff73a1f172025c8ed

Contents?: true

Size: 619 Bytes

Versions: 39

Compression:

Stored size: 619 Bytes

Contents

# frozen_string_literal: true

module Bridgetown
  module Utils
    # Based on the pattern and code from
    # https://emptysqua.re/blog/an-event-synchronization-primitive-for-ruby/
    class ThreadEvent
      attr_reader :flag

      def initialize
        @lock = Mutex.new
        @cond = ConditionVariable.new
        @flag = false
      end

      def set
        @lock.synchronize do
          yield if block_given?
          @flag = true
          @cond.broadcast
        end
      end

      def wait
        @lock.synchronize do
          @cond.wait(@lock) unless @flag
        end
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
bridgetown-core-0.21.0.beta1 lib/bridgetown-core/utils/thread_event.rb
bridgetown-core-0.20.0 lib/bridgetown-core/utils/thread_event.rb
bridgetown-core-0.19.3 lib/bridgetown-core/utils/thread_event.rb
bridgetown-core-0.19.2 lib/bridgetown-core/utils/thread_event.rb
bridgetown-core-0.19.1 lib/bridgetown-core/utils/thread_event.rb
bridgetown-core-0.19.0 lib/bridgetown-core/utils/thread_event.rb
bridgetown-core-0.18.6 lib/bridgetown-core/utils/thread_event.rb
bridgetown-core-0.18.5 lib/bridgetown-core/utils/thread_event.rb
bridgetown-core-0.18.4 lib/bridgetown-core/utils/thread_event.rb
bridgetown-core-0.18.3 lib/bridgetown-core/utils/thread_event.rb
bridgetown-core-0.18.2 lib/bridgetown-core/utils/thread_event.rb
bridgetown-core-0.18.1 lib/bridgetown-core/utils/thread_event.rb
bridgetown-core-0.18.0 lib/bridgetown-core/utils/thread_event.rb
bridgetown-core-0.17.1 lib/bridgetown-core/utils/thread_event.rb
bridgetown-core-0.17.0 lib/bridgetown-core/utils/thread_event.rb
bridgetown-core-0.16.0 lib/bridgetown-core/utils/thread_event.rb
bridgetown-core-0.16.0.beta2 lib/bridgetown-core/utils/thread_event.rb
bridgetown-core-0.16.0.beta1 lib/bridgetown-core/utils/thread_event.rb
bridgetown-core-0.15.0 lib/bridgetown-core/utils/thread_event.rb
bridgetown-core-0.15.0.beta4 lib/bridgetown-core/utils/thread_event.rb