class RollingTimeout
Constants
- VERSION
Public Class Methods
new(time_in_seconds) { |self| ... }
click to toggle source
# File lib/rolling_timeout.rb, line 6 def initialize(time_in_seconds, &block) @time_in_seconds = time_in_seconds start @timed_out = false @code_thread = Thread.new{ yield self } @code_thread.join @timer_thread.join if @timed_out end
Public Instance Methods
reset()
click to toggle source
# File lib/rolling_timeout.rb, line 16 def reset stop start end
start()
click to toggle source
# File lib/rolling_timeout.rb, line 25 def start @timer_thread = new_timer_thread end
stop()
click to toggle source
# File lib/rolling_timeout.rb, line 21 def stop @timer_thread.kill end
Private Instance Methods
new_timer_thread()
click to toggle source
# File lib/rolling_timeout.rb, line 31 def new_timer_thread Thread.new { sleep(@time_in_seconds) @timed_out = true @code_thread.kill raise Timeout::Error } end