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’
Constants
Mutex used to synchronize access across threads
Class Methods
::
lib/webrick/utils.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/webrick/utils.rb, line 143
def TimeoutHandler.cancel(id)
instance.cancel(Thread.current, id)
end
Cancels the timeout handler id
::
lib/webrick/utils.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/webrick/utils.rb, line 154
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.
lib/webrick/utils.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/webrick/utils.rb, line 136
def TimeoutHandler.register(seconds, exception)
at = Process.clock_gettime(Process::CLOCK_MONOTONIC) + seconds
instance.register(Thread.current, at, exception)
end
::
lib/webrick/utils.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/webrick/utils.rb, line 147
def self.terminate
instance.terminate
end
No documentation available