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.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'frugal_timeout'
3
- s.version = '0.0.11'
3
+ s.version = '0.0.12'
4
4
  s.date = '2014-01-03'
5
5
  s.summary = 'Timeout.timeout replacement'
6
6
  s.description = 'Timeout.timeout replacement that uses only 1 thread'
@@ -92,11 +92,15 @@ module FrugalTimeout
92
92
  def_delegators :@requests, :empty?, :first, :<<
93
93
 
94
94
  def initialize
95
- @onNewNearestRequest, @requests = proc {}, SortedQueue.new
95
+ @onNewNearestRequest, @requests, @threadReq =
96
+ proc {}, SortedQueue.new, {}
96
97
  end
97
98
 
98
99
  def defuse_thread! thread
99
- @requests.each { |r| r.defuse! if r.thread == thread }
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frugal_timeout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: