Class: Mongo::ConditionVariable Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/mongo/condition_variable.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.

This is an implementation of a condition variable.

Instance Method Summary collapse

Constructor Details

#initialize(lock = Mutex.new) ⇒ ConditionVariable

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 ConditionVariable.



25
26
27
28
# File 'lib/mongo/condition_variable.rb', line 25

def initialize(lock = Mutex.new)
  @lock = lock
  @cv = ::ConditionVariable.new
end

Instance Method Details

#broadcastObject

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.



38
39
40
41
# File 'lib/mongo/condition_variable.rb', line 38

def broadcast
  raise_unless_locked!
  @cv.broadcast
end

#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.



43
44
45
46
# File 'lib/mongo/condition_variable.rb', line 43

def signal
  raise_unless_locked!
  @cv.signal
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.

Waits for the condition variable to be signaled up to timeout seconds. If condition variable is not signaled, returns after timeout seconds.



32
33
34
35
36
# File 'lib/mongo/condition_variable.rb', line 32

def wait(timeout = nil)
  raise_unless_locked!
  return false if timeout && timeout < 0
  @cv.wait(@lock, timeout)
end