class Mongo::DistinguishingSemaphore
This is a semaphore that distinguishes waits ending due to the timeout being reached from waits ending due to the semaphore being signaled.
@api private
Public Class Methods
Source
# File lib/mongo/distinguishing_semaphore.rb, line 21 def initialize @lock = Mutex.new @cv = ConditionVariable.new @queue = [] end
Public Instance Methods
Source
# File lib/mongo/distinguishing_semaphore.rb, line 41 def broadcast @lock.synchronize do @queue.push(true) @cv.broadcast end end
Source
# File lib/mongo/distinguishing_semaphore.rb, line 48 def signal @lock.synchronize do @queue.push(true) @cv.signal end end
Source
# File lib/mongo/distinguishing_semaphore.rb, line 32 def wait(timeout = nil) @lock.synchronize do @cv.wait(@lock, timeout) (!@queue.empty?).tap do @queue.clear end end end
Waits for the semaphore to be signaled up to timeout seconds. If semaphore is not signaled, returns after timeout seconds.
@return [ true | false ] true if semaphore was signaled, false if
timeout was reached.