mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
merge revision(s) 27394:27397:
* lib/timeout.rb (Timeout#timeout): propagate errors to the caller. [ruby-dev:41010]' git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@28209 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0b1e93285e
commit
1bb0917fa7
3 changed files with 17 additions and 4 deletions
|
|
@ -56,8 +56,13 @@ module Timeout
|
|||
begin
|
||||
x = Thread.current
|
||||
y = Thread.start {
|
||||
sleep sec
|
||||
x.raise exception, "execution expired" if x.alive?
|
||||
begin
|
||||
sleep sec
|
||||
rescue => e
|
||||
x.raise e
|
||||
else
|
||||
x.raise exception, "execution expired" if x.alive?
|
||||
end
|
||||
}
|
||||
yield sec
|
||||
# return true
|
||||
|
|
@ -73,7 +78,10 @@ module Timeout
|
|||
# would be expected outside.
|
||||
raise Error, e.message, e.backtrace
|
||||
ensure
|
||||
y.kill if y and y.alive?
|
||||
if y and y.alive?
|
||||
y.kill
|
||||
y.join # make sure y is dead.
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue