* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@11995 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6dfd5fe953
commit
f24e3f2271
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
|||||||
|
Mon Mar 5 09:19:33 2007 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
Mon Mar 5 09:16:40 2007 Minero Aoki <aamine@loveruby.net>
|
Mon Mar 5 09:16:40 2007 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
* lib/net/smtp.rb: support automatic STARTTLS.
|
* lib/net/smtp.rb: support automatic STARTTLS.
|
||||||
|
@ -27,23 +27,23 @@ module Timeout
|
|||||||
class Error < Interrupt
|
class Error < Interrupt
|
||||||
end
|
end
|
||||||
|
|
||||||
# Executes the method's block. If the block execution terminates before +sec+
|
# Executes the method's block. If the block execution terminates before
|
||||||
# seconds has passed, it returns true. If not, it terminates the execution
|
# +sec+ seconds has passed, it returns the result value of the block.
|
||||||
# and raises +exception+ (which defaults to Timeout::Error).
|
# 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'
|
# 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,
|
# into your classes so they have a #timeout method, as well as a module method,
|
||||||
# so you can call it directly as Timeout.timeout().
|
# so you can call it directly as Timeout.timeout().
|
||||||
def timeout(sec, exception=Error)
|
def timeout(sec, exception = Error) #:yield: +sec+
|
||||||
return yield if sec == nil or sec.zero?
|
return yield(sec) if sec == nil or sec.zero?
|
||||||
begin
|
begin
|
||||||
x = Thread.current
|
x = Thread.current
|
||||||
y = Thread.start {
|
y = Thread.start {
|
||||||
sleep sec
|
sleep sec
|
||||||
x.raise exception, "execution expired" if x.alive?
|
x.raise exception, "execution expired" if x.alive?
|
||||||
}
|
}
|
||||||
yield sec
|
return yield(sec)
|
||||||
return true
|
|
||||||
ensure
|
ensure
|
||||||
y.kill if y and y.alive?
|
y.kill if y and y.alive?
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user