Class: ExitTimer
- Inherits:
-
Object
- Object
- ExitTimer
- Defined in:
- lib/utils/exit_timer.rb
Overview
Timer that exits the process if it expires. Use a timer thread, as the Qpid::Proton::Container does not yet provide scheduled tasks.
Instance Attribute Summary collapse
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#initialize(timeout) ⇒ ExitTimer
constructor
Start the timer to exit after timeout.
-
#reset ⇒ Object
Reset the timer to count to timeout from now.
Constructor Details
#initialize(timeout) ⇒ ExitTimer
Start the timer to exit after timeout.
26 27 28 29 30 31 32 33 34 35 36 37 |
# 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 |
Instance Attribute Details
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
23 24 25 |
# File 'lib/utils/exit_timer.rb', line 23 def timeout @timeout end |
Instance Method Details
#reset ⇒ Object
Reset the timer to count to timeout from now
40 41 42 |
# File 'lib/utils/exit_timer.rb', line 40 def reset() @lock.synchronize { @deadline = Time.now + @timeout } end |