class QuackConcurrency::Waiter

{Waiter} is similar to {ConditionVariable}.

A few differences include:

@api private

Public Class Methods

new() click to toggle source

Creates a new {Waiter} concurrency tool. @return [Waiter]

# File lib/quack_concurrency/waiter.rb, line 16
def initialize
  @condition_variable = SafeConditionVariable.new
  @resume_all_indefinitely = false
  @mutex = ::Mutex.new
end

Public Instance Methods

any_waiting_threads?() click to toggle source

Checks if any threads are waiting on it. @return [Boolean]

# File lib/quack_concurrency/waiter.rb, line 24
def any_waiting_threads?
  @condition_variable.any_waiting_threads?
end
resume_all() click to toggle source

Resumes all threads waiting on it. @return [void]

# File lib/quack_concurrency/waiter.rb, line 30
def resume_all
  @condition_variable.broadcast
end
resume_all_indefinitely() click to toggle source

Resumes all threads waiting on it and will cause

any future calls to {#wait} to return immediately.

@return [void]

# File lib/quack_concurrency/waiter.rb, line 37
def resume_all_indefinitely
  @mutex.synchronize do
    @resume_all_indefinitely = true
    resume_all
  end
end
resume_next() click to toggle source

Resumes next thread waiting on it if one exists. @return [void]

# File lib/quack_concurrency/waiter.rb, line 46
def resume_next
  @condition_variable.signal
end
wait() click to toggle source

Puts this thread to sleep until another thread resumes it via this {Waiter}. @note Will block until resumed. @return [void]

# File lib/quack_concurrency/waiter.rb, line 53
def wait
  @mutex.synchronize do
    return if @resume_all_indefinitely
    @condition_variable.wait(@mutex)
  end
end
waiting_threads_count() click to toggle source

Returns the number of threads waiting on it. @return [Integer]

# File lib/quack_concurrency/waiter.rb, line 62
def waiting_threads_count
  @condition_variable.waiting_threads_count
end