async-pool 0.3.5 → 0.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/async/pool/controller.rb +43 -28
- data/lib/async/pool/resource.rb +5 -1
- data/lib/async/pool/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +34 -34
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63f0054e2d8ce94ab52e1186939e06ae2045edd757ba0ba1e0f0eca0f1ec1f80
|
4
|
+
data.tar.gz: 10d52bf1f00b7e8062b8ee3bbd612c79d0db07e28fa08e6273814eb686861178
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3239399837876e2eb1fa00106eafd1d1e8c78c8eceb840fa5c7a694e4d819931803fd4ea8cc1cd6acc490071d379638463eaee8884d46d721488316e60d3cd48
|
7
|
+
data.tar.gz: 005f0036c7153b774fd31806f206a69a35b394f99cb899498939dc69b4e2e520d34db342c74ff0c7a6b5345ca4db91f0f68bb269dfc9373b3a55236df08d5934
|
checksums.yaml.gz.sig
ADDED
Binary file
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
|
-
require '
|
21
|
+
require 'console/logger'
|
22
22
|
|
23
23
|
require 'async'
|
24
24
|
require 'async/notification'
|
@@ -98,12 +98,14 @@ module Async
|
|
98
98
|
|
99
99
|
# Make the resource resources and let waiting tasks know that there is something resources.
|
100
100
|
def release(resource)
|
101
|
+
processed = false
|
102
|
+
|
101
103
|
# A resource that is not good should also not be reusable.
|
102
104
|
if resource.reusable?
|
103
|
-
reuse(resource)
|
104
|
-
else
|
105
|
-
retire(resource)
|
105
|
+
processed = reuse(resource)
|
106
106
|
end
|
107
|
+
ensure
|
108
|
+
retire(resource) unless processed
|
107
109
|
end
|
108
110
|
|
109
111
|
def close
|
@@ -157,13 +159,15 @@ module Async
|
|
157
159
|
end
|
158
160
|
|
159
161
|
def retire(resource)
|
160
|
-
|
162
|
+
Console.logger.debug(self) {"Retire #{resource}"}
|
161
163
|
|
162
164
|
@resources.delete(resource)
|
163
165
|
|
164
166
|
resource.close
|
165
167
|
|
166
168
|
@notification.signal
|
169
|
+
|
170
|
+
return true
|
167
171
|
end
|
168
172
|
|
169
173
|
protected
|
@@ -207,7 +211,7 @@ module Async
|
|
207
211
|
end
|
208
212
|
|
209
213
|
def reuse(resource)
|
210
|
-
|
214
|
+
Console.logger.debug(self) {"Reuse #{resource}"}
|
211
215
|
usage = @resources[resource]
|
212
216
|
|
213
217
|
if usage.zero?
|
@@ -229,6 +233,8 @@ module Async
|
|
229
233
|
@resources[resource] = usage - 1
|
230
234
|
|
231
235
|
@notification.signal
|
236
|
+
|
237
|
+
return true
|
232
238
|
end
|
233
239
|
|
234
240
|
def wait_for_resource
|
@@ -237,7 +243,7 @@ module Async
|
|
237
243
|
@notification.wait
|
238
244
|
end
|
239
245
|
|
240
|
-
|
246
|
+
Console.logger.debug(self) {"Wait for resource -> #{resource}"}
|
241
247
|
|
242
248
|
# if resource.concurrency > 1
|
243
249
|
# @notification.signal
|
@@ -265,36 +271,45 @@ module Async
|
|
265
271
|
|
266
272
|
# @returns [Object] An existing resource in a "used" state.
|
267
273
|
def available_resource
|
274
|
+
resource = nil
|
275
|
+
|
268
276
|
@guard.acquire do
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
277
|
+
resource = get_resource
|
278
|
+
end
|
279
|
+
|
280
|
+
return resource
|
281
|
+
rescue Exception
|
282
|
+
reuse(resource) if resource
|
283
|
+
raise
|
284
|
+
end
|
285
|
+
|
286
|
+
private def get_resource
|
287
|
+
while resource = @available.last
|
288
|
+
if usage = @resources[resource] and usage < resource.concurrency
|
289
|
+
if resource.viable?
|
290
|
+
usage = (@resources[resource] += 1)
|
291
|
+
|
292
|
+
if usage == resource.concurrency
|
293
|
+
# The resource is used up to it's limit:
|
282
294
|
@available.pop
|
283
295
|
end
|
296
|
+
|
297
|
+
return resource
|
284
298
|
else
|
285
|
-
|
299
|
+
retire(resource)
|
286
300
|
@available.pop
|
287
301
|
end
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
Async.logger.debug(self) {"No available resources, allocating new one..."}
|
292
|
-
|
293
|
-
return create_resource
|
302
|
+
else
|
303
|
+
# The resource has been removed already, so skip it and remove it from the availability list.
|
304
|
+
@available.pop
|
294
305
|
end
|
295
306
|
end
|
296
307
|
|
297
|
-
|
308
|
+
if @limit.nil? or @resources.size < @limit
|
309
|
+
Console.logger.debug(self) {"No available resources, allocating new one..."}
|
310
|
+
|
311
|
+
return create_resource
|
312
|
+
end
|
298
313
|
end
|
299
314
|
end
|
300
315
|
end
|
data/lib/async/pool/resource.rb
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
|
-
require '
|
21
|
+
require 'console/logger'
|
22
22
|
|
23
23
|
require 'async/notification'
|
24
24
|
require 'async/semaphore'
|
@@ -58,6 +58,10 @@ module Async
|
|
58
58
|
|
59
59
|
# Close the resource explicitly, e.g. the pool is being closed.
|
60
60
|
def close
|
61
|
+
if @closed
|
62
|
+
raise "Already closed!"
|
63
|
+
end
|
64
|
+
|
61
65
|
@closed = true
|
62
66
|
end
|
63
67
|
|
data/lib/async/pool/version.rb
CHANGED
data.tar.gz.sig
ADDED
Binary file
|
metadata
CHANGED
@@ -1,27 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async-pool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
|
-
cert_chain:
|
11
|
-
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIEhDCCAuygAwIBAgIBATANBgkqhkiG9w0BAQsFADA3MTUwMwYDVQQDDCxzYW11
|
14
|
+
ZWwud2lsbGlhbXMvREM9b3Jpb250cmFuc2Zlci9EQz1jby9EQz1uejAeFw0yMTA4
|
15
|
+
MTYwNjMzNDRaFw0yMjA4MTYwNjMzNDRaMDcxNTAzBgNVBAMMLHNhbXVlbC53aWxs
|
16
|
+
aWFtcy9EQz1vcmlvbnRyYW5zZmVyL0RDPWNvL0RDPW56MIIBojANBgkqhkiG9w0B
|
17
|
+
AQEFAAOCAY8AMIIBigKCAYEAyXLSS/cw+fXJ5e7hi+U/TeChPWeYdwJojDsFY1xr
|
18
|
+
xvtqbTTL8gbLHz5LW3QD2nfwCv3qTlw0qI3Ie7a9VMJMbSvgVEGEfQirqIgJXWMj
|
19
|
+
eNMDgKsMJtC7u/43abRKx7TCURW3iWyR19NRngsJJmaR51yGGGm2Kfsr+JtKKLtL
|
20
|
+
L188Wm3f13KAx7QJU8qyuBnj1/gWem076hzdA7xi1DbrZrch9GCRz62xymJlrJHn
|
21
|
+
9iZEZ7AxrS7vokhMlzSr/XMUihx/8aFKtk+tMLClqxZSmBWIErWdicCGTULXCBNb
|
22
|
+
E/mljo4zEVKhlTWpJklMIhr55ZRrSarKFuW7en0+tpJrfsYiAmXMJNi4XAYJH7uL
|
23
|
+
rgJuJwSaa/dMz+VmUoo7VKtSfCoOI+6v5/z0sK3oT6sG6ZwyI47DBq2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em::Dependency
|
14
42
|
name: async
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
16
44
|
requirements:
|
17
|
-
- - "
|
45
|
+
- - ">="
|
18
46
|
- !ruby/object:Gem::Version
|
19
47
|
version: '1.25'
|
20
48
|
type: :runtime
|
21
49
|
prerelease: false
|
22
50
|
version_requirements: !ruby/object:Gem::Requirement
|
23
51
|
requirements:
|
24
|
-
- - "
|
52
|
+
- - ">="
|
25
53
|
- !ruby/object:Gem::Version
|
26
54
|
version: '1.25'
|
27
55
|
- !ruby/object:Gem::Dependency
|
@@ -38,34 +66,6 @@ dependencies:
|
|
38
66
|
- - "~>"
|
39
67
|
- !ruby/object:Gem::Version
|
40
68
|
version: '1.1'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: bake-bundler
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: bake-modernize
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bundler
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: '0'
|
140
140
|
requirements: []
|
141
|
-
rubygems_version: 3.1.
|
141
|
+
rubygems_version: 3.1.6
|
142
142
|
signing_key:
|
143
143
|
specification_version: 4
|
144
144
|
summary: A singleplex and multiplex resource pool for implementing robust clients.
|
metadata.gz.sig
ADDED
Binary file
|