Project

General

Profile

Feature #11650 ยป feature.diff

kirs (Kir Shatrov), 11/03/2015 10:26 AM

View differences:

lib/timeout.rb
# value of 0 or +nil+ will execute the block without any timeout.
# +klass+:: Exception Class to raise if the block fails to terminate
# in +sec+ seconds. Omitting will use the default, Timeout::Error
# +message+:: Error message to rasise with Exception Class.
# Omitting will use the default, "execution expired"
#
# Returns the result of the block *if* the block completed before
# +sec+ seconds, otherwise throws an exception, based on the value of +klass+.
......
# Note that this is both a method of module Timeout, so you can <tt>include
# Timeout</tt> into your classes so they have a #timeout method, as well as
# a module method, so you can call it directly as Timeout.timeout().
def timeout(sec, klass = nil) #:yield: +sec+
def timeout(sec, klass = nil, message = nil) #:yield: +sec+
return yield(sec) if sec == nil or sec.zero?
message = "execution expired".freeze
message ||= "execution expired".freeze
e = Error
bl = proc do |exception|
begin
test/test_timeout.rb
sleep 3
end
end
assert_raise_with_message(err, /connection to rubylang.org expired/) do
Timeout.timeout 0.01, err, "connection to rubylang.org expired" do
sleep 3
end
end
end
def test_exit_exception
    (1-1/1)