Sha256: 4ecc35dd6b0639a3bfb4950bcc6460b0d72bdeeb73287bea8be8828567503542

Contents?: true

Size: 659 Bytes

Versions: 21

Compression:

Stored size: 659 Bytes

Contents

# frozen_string_literal: true

require "thread"

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
          unless @flag
            @cond.wait(@lock)
          end
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
jekyll-3.10.0 lib/jekyll/utils/thread_event.rb
jekyll-3.9.5 lib/jekyll/utils/thread_event.rb
jekyll-3.9.4 lib/jekyll/utils/thread_event.rb
jekyll-3.9.3 lib/jekyll/utils/thread_event.rb
jekyll-3.9.2 lib/jekyll/utils/thread_event.rb
jekyll-3.9.1 lib/jekyll/utils/thread_event.rb
jekyll-3.9.0 lib/jekyll/utils/thread_event.rb
jekyll-3.8.7 lib/jekyll/utils/thread_event.rb
jekyll-3.8.6 lib/jekyll/utils/thread_event.rb
jekyll-3.8.5 lib/jekyll/utils/thread_event.rb
jekyll-3.8.4 lib/jekyll/utils/thread_event.rb
jekyll-3.7.4 lib/jekyll/utils/thread_event.rb
jekyll-3.8.3 lib/jekyll/utils/thread_event.rb
jekyll-3.8.2 lib/jekyll/utils/thread_event.rb
jekyll-3.8.1 lib/jekyll/utils/thread_event.rb
jekyll-3.8.0 lib/jekyll/utils/thread_event.rb
jekyll-3.8.0.pre.rc2 lib/jekyll/utils/thread_event.rb
jekyll-3.8.0.pre.rc1 lib/jekyll/utils/thread_event.rb
jekyll-3.7.3 lib/jekyll/utils/thread_event.rb
jekyll-3.7.2 lib/jekyll/utils/thread_event.rb