![show/hide quicksearch [+]](../../images/find.png)
Class used to manage timeout handlers across multiple threads.
Timeout handlers should be managed by using the class methods which are synchronized.
id = TimeoutHandler.register(10, Timeout::Error) begin sleep 20 puts 'foo' ensure TimeoutHandler.cancel(id) end
will raise Timeout::Error
id = TimeoutHandler.register(10, Timeout::Error) begin sleep 5 puts 'foo' ensure TimeoutHandler.cancel(id) end
will print ‘foo’
Cancels the timeout handler id
 
               # File webrick/utils.rb, line 142
def TimeoutHandler.cancel(id)
  instance.cancel(Thread.current, id)
end
             
            Creates a new TimeoutHandler. You should use ::register and ::cancel instead of creating the timeout handler directly.
 
               # File webrick/utils.rb, line 153
def initialize
  TimeoutMutex.synchronize{
    @timeout_info = Hash.new
  }
  @queue = Thread::Queue.new
  @watcher = nil
end
             
            Registers a new timeout handler
time
Timeout in seconds
exception
Exception to raise when timeout elapsed
 
               # File webrick/utils.rb, line 135
def TimeoutHandler.register(seconds, exception)
  at = Process.clock_gettime(Process::CLOCK_MONOTONIC) + seconds
  instance.register(Thread.current, at, exception)
end