Permalink
Browse files

it's alive!

  • Loading branch information...
1 parent 4b956cd commit 354f4e607e928d4e9b0324bc458261b830e75997 @jjb committed Sep 15, 2012
Showing with 5 additions and 3 deletions.
  1. +5 −3 sane-timeout.rb
View
8 sane-timeout.rb
@@ -55,17 +55,19 @@ def timeout(sec, klass = nil) #:yield: +sec+
exception = klass || Class.new(ExitException)
begin
begin
- x = Thread.current
+ current_thread = Thread.current
+ x = Thread.start{ yield(sec) }
y = Thread.start {
begin
sleep sec
rescue => e
x.raise e
else
- x.raise exception, "execution expired"
+ x.kill
+ current_thread.raise exception, "execution expired"
end
}
- return yield(sec)
+ x.value
ensure
if y
y.kill

0 comments on commit 354f4e6

Please sign in to comment.