frugal_timeout 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/frugal_timeout.gemspec +1 -1
- data/lib/frugal_timeout.rb +21 -2
- metadata +1 -1
data/frugal_timeout.gemspec
CHANGED
data/lib/frugal_timeout.rb
CHANGED
@@ -92,11 +92,15 @@ module FrugalTimeout
|
|
92
92
|
def_delegators :@requests, :empty?, :first, :<<
|
93
93
|
|
94
94
|
def initialize
|
95
|
-
@onNewNearestRequest, @requests =
|
95
|
+
@onNewNearestRequest, @requests, @threadReq =
|
96
|
+
proc {}, SortedQueue.new, {}
|
96
97
|
end
|
97
98
|
|
98
99
|
def defuse_thread! thread
|
99
|
-
@requests.
|
100
|
+
@requests.synchronize {
|
101
|
+
stored = @threadReq.delete thread
|
102
|
+
stored.each { |r| r.defuse! } if stored.is_a? Array
|
103
|
+
}
|
100
104
|
end
|
101
105
|
private :defuse_thread!
|
102
106
|
|
@@ -130,11 +134,26 @@ module FrugalTimeout
|
|
130
134
|
}
|
131
135
|
end
|
132
136
|
|
137
|
+
def storeInIndex request
|
138
|
+
unless stored = @threadReq[request.thread]
|
139
|
+
@threadReq[request.thread] = request
|
140
|
+
return
|
141
|
+
end
|
142
|
+
|
143
|
+
if stored.is_a? Array
|
144
|
+
stored << request
|
145
|
+
else
|
146
|
+
@threadReq[request.thread] = [stored, request]
|
147
|
+
end
|
148
|
+
end
|
149
|
+
private :storeInIndex
|
150
|
+
|
133
151
|
def queue sec, klass
|
134
152
|
@requests.synchronize {
|
135
153
|
@requests << (request = Request.new(Thread.current,
|
136
154
|
MonotonicTime.now + sec, klass))
|
137
155
|
@onNewNearestRequest.call(request) if @requests.first == request
|
156
|
+
storeInIndex request
|
138
157
|
request
|
139
158
|
}
|
140
159
|
end
|