summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--lib/timeout.rb14
2 files changed, 17 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 307ec428d5..043147c411 100644
--- a/ChangeLog
+++ b/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>
* lib/net/smtp.rb: support automatic STARTTLS.
diff --git a/lib/timeout.rb b/lib/timeout.rb
index af201c8ee7..19045d9491 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