class Jekyll::Utils::ThreadEvent

Based on the pattern and code from emptysqua.re/blog/an-event-synchronization-primitive-for-ruby/

Attributes

flag[R]

Public Class Methods

new() click to toggle source
# File lib/jekyll/utils/thread_event.rb, line 10
def initialize
  @lock = Mutex.new
  @cond = ConditionVariable.new
  @flag = false
end

Public Instance Methods

set() { || ... } click to toggle source
# File lib/jekyll/utils/thread_event.rb, line 16
def set
  @lock.synchronize do
    yield if block_given?
    @flag = true
    @cond.broadcast
  end
end
wait() click to toggle source
# File lib/jekyll/utils/thread_event.rb, line 24
def wait
  @lock.synchronize do
    @cond.wait(@lock) unless @flag
  end
end