class ExitTimer
Timer that exits the process if it expires. Use a timer thread, as the Qpid::Proton::Container does not yet provide scheduled tasks.
Attributes
timeout[R]
Public Class Methods
new(timeout)
click to toggle source
Start the timer to exit after timeout.
# File lib/utils/exit_timer.rb, line 26 def initialize(timeout) @timeout = timeout @lock = Mutex.new reset Thread.new do while (delta = @lock.synchronize { @deadline - Time.now } ) > 0 sleep delta end puts "timeout expired" exit(0) end end
Public Instance Methods
reset()
click to toggle source
Reset the timer to count to timeout from now
# File lib/utils/exit_timer.rb, line 40 def reset() @lock.synchronize { @deadline = Time.now + @timeout } end