frugal_timeout 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/frugal_timeout.rb +5 -6
- metadata +1 -1
data/lib/frugal_timeout.rb
CHANGED
@@ -14,8 +14,8 @@ module FrugalTimeout
|
|
14
14
|
|
15
15
|
attr_reader :at, :thread
|
16
16
|
|
17
|
-
def initialize thread, at
|
18
|
-
@thread, @at = thread, at
|
17
|
+
def initialize thread, at, klass
|
18
|
+
@thread, @at, @klass = thread, at, klass
|
19
19
|
end
|
20
20
|
|
21
21
|
def <=>(other)
|
@@ -31,7 +31,7 @@ module FrugalTimeout
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def enforceTimeout
|
34
|
-
@thread.raise Error, 'execution expired' unless done?
|
34
|
+
@thread.raise @klass || Error, 'execution expired' unless done?
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -94,9 +94,8 @@ module FrugalTimeout
|
|
94
94
|
}
|
95
95
|
start = Time.now
|
96
96
|
sleepFor ? sleep(sleepFor) : sleep
|
97
|
-
slept = Time.now - start
|
98
97
|
@sleeperMutex.synchronize {
|
99
|
-
@in.push :expired if sleepFor &&
|
98
|
+
@in.push :expired if sleepFor && Time.now - start >= sleepFor
|
100
99
|
}
|
101
100
|
}
|
102
101
|
}
|
@@ -119,7 +118,7 @@ module FrugalTimeout
|
|
119
118
|
end
|
120
119
|
|
121
120
|
def self.timeout t, klass=nil
|
122
|
-
@in.push request = Request.new(Thread.current, Time.now + t)
|
121
|
+
@in.push request = Request.new(Thread.current, Time.now + t, klass)
|
123
122
|
begin
|
124
123
|
yield t
|
125
124
|
ensure
|