class Concurrent::Event

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/concurrent-ruby/concurrent/atomic/event.rbs

class Concurrent::Event < Concurrent::Synchronization::LockableObject
  def initialize: () -> void
  def ns_initialize: () -> Integer
  def ns_set: () -> true
  def reset: () -> untyped
  def set: () -> true
  def set?: () -> untyped
  def wait: (?Float timeout) -> untyped
end

# event occurred
# t2 calling set
# t1 is waiting
# prints:
[t1, t2].each(&:join)
end
event.set
puts “t2 calling set”
t2 = Thread.new do
end
puts “event occurred”
event.wait(1)
puts “t1 is waiting”
t1 = Thread.new do
event = Concurrent::Event.new
@example
@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

Experimental RBS support (using type sampling data from the type_fusion project).

def initialize: () -> void

This signature was generated using 5 samples from 2 applications.

`Event` will block.
Creates a new `Event` in the unset state. Threads calling `#wait` on the
def initialize
  super
  synchronize { ns_initialize }
end

def ns_initialize

Experimental RBS support (using type sampling data from the type_fusion project).

def ns_initialize: () -> Integer

This signature was generated using 1 sample from 1 application.

def ns_initialize
  @set       = false
  @iteration = 0
end

def ns_set

Experimental RBS support (using type sampling data from the type_fusion project).

def ns_set: () -> true

This signature was generated using 1 sample from 1 application.

def ns_set
  unless @set
    @set = true
    ns_broadcast
  end
  true
end

def reset

Experimental RBS support (using type sampling data from the type_fusion project).

def reset: () -> untyped

This signature was generated using 1 sample from 1 application.

Returns:
  • (Boolean) - should always return `true`
def reset
  synchronize do
    if @set
      @set       = false
      @iteration +=1
    end
    true
  end
end

def set

Experimental RBS support (using type sampling data from the type_fusion project).

def set: () -> true

This signature was generated using 3 samples from 3 applications.

Returns:
  • (Boolean) - should always return `true`
def set
  synchronize { ns_set }
end

def set?

Experimental RBS support (using type sampling data from the type_fusion project).

def set?: () -> untyped

This signature was generated using 4 samples from 1 application.

Returns:
  • (Boolean) - indicating whether or not the `Event` has been set
def set?
  synchronize { @set }
end

def try?

def try?
  synchronize { @set ? false : ns_set }
end

def wait(timeout = nil)

Experimental RBS support (using type sampling data from the type_fusion project).

def wait: (?Float timeout) -> untyped

This signature was generated using 1 sample from 1 application.

Returns:
  • (Boolean) - true if the `Event` was set before timeout else false
def wait(timeout = nil)
  synchronize do
    unless @set
      iteration = @iteration
      ns_wait_until(timeout) { iteration < @iteration || @set }
    else
      true
    end
  end
end