diff options
author | aamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-03-05 00:20:05 +0000 |
---|---|---|
committer | aamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-03-05 00:20:05 +0000 |
commit | c86a4b38e06e6e4dafd11580e739c365e3a73ed9 (patch) | |
tree | def1cede9f98c3b084b00c3d937f4a7fb58af150 /lib/timeout.rb | |
parent | e4ec6e9ec0fb58b24be00930c8c0e57342a439e3 (diff) | |
download | ruby-c86a4b38e06e6e4dafd11580e739c365e3a73ed9.tar.gz ruby-c86a4b38e06e6e4dafd11580e739c365e3a73ed9.tar.xz ruby-c86a4b38e06e6e4dafd11580e739c365e3a73ed9.zip |
* lib/timeout.rb (Timeout.timeout): should return the block value always.
* lib/timeout.rb (Timeout.timeout): should yield sec argument always.
* lib/timeout.rb (Timeout.timeout): fix document.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@11995 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/timeout.rb')
-rw-r--r-- | lib/timeout.rb | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/timeout.rb b/lib/timeout.rb index af201c8ee..19045d949 100644 --- a/lib/timeout.rb +++ b/lib/timeout.rb @@ -27,23 +27,23 @@ module Timeout class Error < Interrupt end - # Executes the method's block. If the block execution terminates before +sec+ - # seconds has passed, it returns true. If not, it terminates the execution - # and raises +exception+ (which defaults to Timeout::Error). + # Executes the method's block. If the block execution terminates before + # +sec+ seconds has passed, it returns the result value of the block. + # If not, it terminates the execution and raises +exception+ (which defaults + # to Timeout::Error). # # Note that this is both a method of module Timeout, so you can 'include Timeout' # 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, exception=Error) - return yield if sec == nil or sec.zero? + def timeout(sec, exception = Error) #:yield: +sec+ + return yield(sec) if sec == nil or sec.zero? begin x = Thread.current y = Thread.start { sleep sec x.raise exception, "execution expired" if x.alive? } - yield sec - return true + return yield(sec) ensure y.kill if y and y.alive? end |