Permalink
Browse files

it's alive!

  • Loading branch information...
jjb committed Sep 15, 2012
1 parent 4b956cd commit 2bfd30b1354251511e753de806b2982c21167ee7
Showing with 9 additions and 3 deletions.
  1. +9 −3 sane-timeout.rb
@@ -55,17 +55,23 @@ 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
# x.join
current_thread.raise exception, "execution expired"
end
}
return yield(sec)
x.value
ensure
if y
y.kill

0 comments on commit 2bfd30b

Please sign in to comment.