Class: Datadog::Core::Semaphore Private

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/core/semaphore.rb

Overview

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.

Semaphore pattern implementation, as described in documentation for ConditionVariable.

Instance Method Summary collapse

Constructor Details

#initializeSemaphore

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 a new instance of Semaphore.



10
11
12
13
# File 'lib/datadog/core/semaphore.rb', line 10

def initialize
  @wake_lock = Mutex.new
  @wake = ConditionVariable.new
end

Instance Method Details

#signalObject

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.



15
16
17
18
19
# File 'lib/datadog/core/semaphore.rb', line 15

def signal
  wake_lock.synchronize do
    wake.signal
  end
end

#wait(timeout = nil) ⇒ Object

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.



21
22
23
24
25
26
27
28
# File 'lib/datadog/core/semaphore.rb', line 21

def wait(timeout = nil)
  wake_lock.synchronize do
    # steep specifies that the second argument to wait is of type
    # ::Time::_Timeout which for some reason is not Numeric and is not
    # castable from Numeric.
    wake.wait(wake_lock, timeout) # steep:ignore
  end
end