aboutsummaryrefslogtreecommitdiffstats
path: root/lib/timeout.rb
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-07 10:36:59 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-07 10:36:59 +0000
commit3bbffbc7dd024179777192950ac07b9ef6ca2968 (patch)
tree01b93fdd18dcca5efa724c89cc33e11523102677 /lib/timeout.rb
parent65129f3a5dfbfd820f9ad96268f6992f667efe8d (diff)
downloadruby-3bbffbc7dd024179777192950ac07b9ef6ca2968.tar.gz
Revert r38216 and r38221. Release manager mark this feature as "next minor".
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38260 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/timeout.rb')
-rw-r--r--lib/timeout.rb36
1 files changed, 17 insertions, 19 deletions
diff --git a/lib/timeout.rb b/lib/timeout.rb
index 127bccf924..7fd87ff40b 100644
--- a/lib/timeout.rb
+++ b/lib/timeout.rb
@@ -47,28 +47,26 @@ module Timeout
# 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, immediate: false) #:yield: +sec+
+ def timeout(sec, klass = nil) #:yield: +sec+
return yield(sec) if sec == nil or sec.zero?
exception = klass || Class.new(ExitException)
begin
- Thread.async_interrupt_timing(exception => immediate ? :immediate : :on_blocking) do
- begin
- x = Thread.current
- y = Thread.start {
- begin
- sleep sec
- rescue => e
- x.raise e
- else
- x.raise exception, "execution expired"
- end
- }
- return yield(sec)
- ensure
- if y
- y.kill
- y.join # make sure y is dead.
+ begin
+ x = Thread.current
+ y = Thread.start {
+ begin
+ sleep sec
+ rescue => e
+ x.raise e
+ else
+ x.raise exception, "execution expired"
end
+ }
+ return yield(sec)
+ ensure
+ if y
+ y.kill
+ y.join # make sure y is dead.
end
end
rescue exception => e
@@ -80,7 +78,7 @@ module Timeout
level += 1
end
raise if klass # if exception class is specified, it
- # would be expected outside.
+ # would be expected outside.
raise Error, e.message, e.backtrace
end
end