@@ -141,9 +141,10 @@ def self.ensure_timeout_thread_created
141
141
# Perform an operation in a block, raising an error if it takes longer than
142
142
# +sec+ seconds to complete.
143
143
#
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
146
146
# value of 0 or +nil+ will execute the block without any timeout.
147
+ # Any negative value will raise the ArgumentError
147
148
# +klass+:: Exception Class to raise if the block fails to terminate
148
149
# in +sec+ seconds. Omitting will use the default, Timeout::Error
149
150
# +message+:: Error message to raise with Exception Class.
@@ -164,8 +165,8 @@ def self.ensure_timeout_thread_created
164
165
# Timeout</tt> into your classes so they have a #timeout method, as well as
165
166
# a module method, so you can call it directly as Timeout.timeout().
166
167
def timeout ( sec , klass = nil , message = nil , &block ) #:yield: +sec+
167
- raise ArgumentError , "Timeout sec must be a positive number" unless sec . is_a? ( Numeric ) && sec >= 0
168
- return yield ( sec ) if sec . zero?
168
+ raise ArgumentError , "Timeout sec must be a non-negative number" if sec && ! ( sec . is_a? ( Numeric ) && sec >= 0 )
169
+ return yield ( sec ) if sec == nil or sec . zero?
169
170
170
171
message ||= "execution expired"
171
172
0 commit comments