2020
2121module Gem ::Timeout
2222 # The version
23- VERSION = "0.4.2 "
23+ VERSION = "0.4.3 "
2424
2525 # Internal error raised to when a timeout is triggered.
2626 class ExitException < Exception
@@ -141,9 +141,10 @@ def self.ensure_timeout_thread_created
141141 # Perform an operation in a block, raising an error if it takes longer than
142142 # +sec+ seconds to complete.
143143 #
144- # +sec+:: Number of seconds to wait for the block to terminate. Any number
145- # may be used, including Floats to specify fractional seconds. A
144+ # +sec+:: Number of seconds to wait for the block to terminate. Any non-negative number
145+ # or nil may be used, including Floats to specify fractional seconds. A
146146 # value of 0 or +nil+ will execute the block without any timeout.
147+ # Any negative number will raise an ArgumentError.
147148 # +klass+:: Exception Class to raise if the block fails to terminate
148149 # in +sec+ seconds. Omitting will use the default, Gem::Timeout::Error
149150 # +message+:: Error message to raise with Exception Class.
@@ -165,6 +166,7 @@ def self.ensure_timeout_thread_created
165166 # a module method, so you can call it directly as Gem::Timeout.timeout().
166167 def timeout ( sec , klass = nil , message = nil , &block ) #:yield: +sec+
167168 return yield ( sec ) if sec == nil or sec . zero?
169+ raise ArgumentError , "Timeout sec must be a non-negative number" if 0 > sec
168170
169171 message ||= "execution expired"
170172
0 commit comments