Class: QuackConcurrency::Waiter Private

Inherits:
Object
  • Object
show all
Defined in:
lib/quack_concurrency/waiter.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initializeWaiter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a new QuackConcurrency::Waiter concurrency tool.



8
9
10
11
12
# File 'lib/quack_concurrency/waiter.rb', line 8

def initialize
  @condition_variable = UninterruptibleConditionVariable.new
  @resume_all_forever = false
  @mutex = ::Mutex.new
end

Instance Method Details

#any_waiting_threads?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


14
15
16
# File 'lib/quack_concurrency/waiter.rb', line 14

def any_waiting_threads?
  @condition_variable.any_waiting_threads?
end

#resume_allvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Resumes all current and future waiting Thread.



20
21
22
23
# File 'lib/quack_concurrency/waiter.rb', line 20

def resume_all
  @condition_variable.broadcast
  nil
end

#resume_all_forevervoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Resumes all current and future waiting Thread.



27
28
29
30
31
32
33
# File 'lib/quack_concurrency/waiter.rb', line 27

def resume_all_forever
  @mutex.synchronize do
    @resume_all_forever = true
    resume_all
  end
  nil
end

#resume_onevoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Resumes next waiting Thread if one exists.



37
38
39
40
# File 'lib/quack_concurrency/waiter.rb', line 37

def resume_one
  @condition_variable.signal
  nil
end

#waitvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

Will block until resumed.

This method returns an undefined value.

Waits for another Thread to resume the calling Thread.



45
46
47
48
49
50
51
# File 'lib/quack_concurrency/waiter.rb', line 45

def wait
  @mutex.synchronize do
    return if @resume_all_forever
    @condition_variable.wait(@mutex)
  end
  nil
end

#waiting_threads_countObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
# File 'lib/quack_concurrency/waiter.rb', line 53

def waiting_threads_count
  @condition_variable.waiting_threads_count
end