Bug #4285 » timeout.rb.diff
timeout.rb 2011-01-17 18:35:28.976375000 +0100 | ||
---|---|---|
#
|
||
# Copyright:: (C) 2000 Network Applied Communication Laboratory, Inc.
|
||
# Copyright:: (C) 2000 Information-technology Promotion Agency, Japan
|
||
require 'thread'
|
||
module Timeout
|
||
# Raised by Timeout#timeout when the block times out.
|
||
class Error < RuntimeError
|
||
... | ... | |
exception = klass || Class.new(ExitException)
|
||
begin
|
||
x = Thread.current
|
||
y = Thread.start {
|
||
begin
|
||
sleep sec
|
||
rescue => e
|
||
x.raise e
|
||
else
|
||
x.raise exception, "execution expired" if x.alive?
|
||
end
|
||
m = Mutex.new
|
||
m.synchronize {
|
||
y = Thread.start {
|
||
m.synchronize {} # ensure variable y is pointing to the thread
|
||
# before y starts the timer
|
||
begin
|
||
sleep sec
|
||
rescue => e
|
||
x.raise e
|
||
else
|
||
x.raise exception, "execution expired" if x.alive?
|
||
end
|
||
}
|
||
}
|
||
return yield(sec)
|
||
rescue exception => e
|
- « Previous
- 1
- 2
- Next »