Sha256: bd08311be36a8b7312546c83e6bc48413838e8d7df43a7d9e6d2df3f711105e6

Contents?: true

Size: 646 Bytes

Versions: 2

Compression:

Stored size: 646 Bytes

Contents

# frozen_string_literal: true

module Jekyll
  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

2 entries across 2 versions & 2 rubygems

Version Path
jekyll-4.2.1 lib/jekyll/utils/thread_event.rb
ngage-0.0.0 lib/ngage/jekyll/utils/thread_event.rb