Class: ConditionVariable
Instance Method Summary collapse
Instance Method Details
#wait(mutex, timeout = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rbot/compat19.rb', line 11 def wait(mutex, timeout=nil) begin # TODO: mutex should not be used @waiters_mutex.synchronize do @waiters.push(Thread.current) end if timeout elapsed = mutex.sleep timeout if timeout > 0.0 unless timeout > 0.0 and elapsed < timeout t = @waiters_mutex.synchronize { @waiters.delete Thread.current } signal unless t # if we got notified, pass it along raise TimeoutError, "wait timed out" end else mutex.sleep end end nil end |