class WEBrick::Utils::TimeoutHandler
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’
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’
Public Class Methods
(Integer id) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/webrick-1.9.2/lib/webrick/utils.rb, line 137 def TimeoutHandler.cancel(id) instance.cancel(Thread.current, id) end
Cancels the timeout handler id
Cancels the timeout handler +id+
() → void
Source
# File vendor/bundle/ruby/4.0.0/gems/webrick-1.9.2/lib/webrick/utils.rb, line 148 def initialize TimeoutMutex.synchronize{ @timeout_info = Hash.new } @queue = Thread::Queue.new @watcher = nil end
Creates a new TimeoutHandler. You should use ::register and ::cancel instead of creating the timeout handler directly.
Creates a new TimeoutHandler. You should use ::register and ::cancel instead of creating the timeout handler directly.
# File vendor/bundle/ruby/4.0.0/gems/webrick-1.9.2/lib/webrick/utils.rb, line 130 def TimeoutHandler.register(seconds, exception) at = Process.clock_gettime(Process::CLOCK_MONOTONIC) + seconds instance.register(Thread.current, at, exception) end
() → Thread?
Source
# File vendor/bundle/ruby/4.0.0/gems/webrick-1.9.2/lib/webrick/utils.rb, line 141 def self.terminate instance.terminate end
Public Instance Methods
# File vendor/bundle/ruby/4.0.0/gems/webrick-1.9.2/sig/utils.rbs, line 109
def cancel: (Thread thread, Integer id) -> bool
Cancels the timeout handler +id+
# File vendor/bundle/ruby/4.0.0/gems/webrick-1.9.2/sig/utils.rbs, line 98
def interrupt: (Thread thread, Integer id, singleton(Exception) exception) -> nil
Interrupts the timeout handler +id+ and raises +exception+
# File vendor/bundle/ruby/4.0.0/gems/webrick-1.9.2/sig/utils.rbs, line 105
def register: (Thread thread, Numeric time, singleton(Exception) exception) -> Integer
# File vendor/bundle/ruby/4.0.0/gems/webrick-1.9.2/sig/utils.rbs, line 112
def terminate: () -> Thread?
() → bot
Source
# File vendor/bundle/ruby/4.0.0/gems/webrick-1.9.2/sig/utils.rbs, line 90
def watch: () -> bot