class Concurrent::Event

@see msdn.microsoft.com/en-us/library/windows/desktop/ms682655.aspx<br><br>‘#reset` at any time once it has been set.
New threads calling `#wait` will return immediately. An `Event` may be
will then wake up all listeners. Once an `Event` has been set it remains set.
thread wants to alert all blocking threads it calls the `#set` method which
`#wait` on the event, blocking until released by another thread. When one
When an `Event` is created it is in the `unset` state. Threads can choose to
Old school kernel-style event reminiscent of Win32 programming in C++.

def initialize

`Event` will block.
Creates a new `Event` in the unset state. Threads calling `#wait` on the
def initialize
  @set = false
  @mutex = Mutex.new
  @condition = Condition.new
end

def reset

Returns:
  • (Boolean) - should always return `true`
def reset
  @mutex.lock
  @set = false
  @mutex.unlock
  true
end

def set

Returns:
  • (Boolean) - should always return `true`
def set
  @mutex.lock
  unless @set
    @set = true
    @condition.broadcast
  end
  @mutex.unlock
  true
end

def set?

Returns:
  • (Boolean) - indicating whether or not the `Event` has been set
def set?
  @mutex.lock
  result = @set
  @mutex.unlock
  result
end

def try?

def try?
  @mutex.lock
  if @set
    result = false
  else
    @set = true
    @condition.broadcast
    result = true
  end
  @mutex.unlock
  result
end

def wait(timeout = nil)

Returns:
  • (Boolean) - true if the `Event` was set before timeout else false
def wait(timeout = nil)
  @mutex.lock
  unless @set
    remaining = Condition::Result.new(timeout)
    while !@set && remaining.can_wait?
      remaining = @condition.wait(@mutex, remaining.remaining_time)
    end
  end
  result = @set
  @mutex.unlock
  result
end