async-pool 0.11.0 → 0.11.2
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 +17 -17
- data/lib/async/pool/version.rb +1 -1
- data/lib/traces/provider/async/pool/controller.rb +5 -5
- data/license.md +2 -1
- data/readme.md +1 -1
- data/releases.md +1 -1
- data.tar.gz.sig +0 -0
- metadata +3 -2
- 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: e4fe0a9bc65859c5bcb987643f591473236e1fdb2b296c9d73dc9750c01b44ff
|
|
4
|
+
data.tar.gz: 116b1ec100edce9d7bbf85fe57a41d7f7059ed495eca17c8d96940a6c10e7724
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c17cc32005753a5f3141aa4a198c5a1b826a212c44f05a382951561bd3b274aaa66e6f0d8f77e21bd613b42f4ab1a6a0d51f9463abd4ecc33f42a5b1e46642b8
|
|
7
|
+
data.tar.gz: 326fdcd55c875d840d02d1d9fe73082edb70d83361a4a2e1cde34331ded7b3bb184a436ec8907e3c0065c3444554a56eaa89817dd25ceb2936fbf3ff96b23ada
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
# Copyright, 2020, by Simon Perepelitsa.
|
|
6
6
|
# Copyright, 2024, by Thomas Morgan.
|
|
7
7
|
# Copyright, 2025, by Jean Boussier.
|
|
8
|
+
# Copyright, 2026, by William T. Nelson.
|
|
8
9
|
|
|
9
10
|
require "console/logger"
|
|
10
11
|
|
|
@@ -26,9 +27,9 @@ module Async
|
|
|
26
27
|
#
|
|
27
28
|
# @parameter constructor [Proc] A block which creates a new resource.
|
|
28
29
|
# @parameter limit [Integer | Nil] The maximum number of resources that this pool can have at any given time. If nil, the pool can have an unlimited number of resources.
|
|
29
|
-
# @parameter concurrency [Integer] The maximum number of concurrent tasks that can be creating a new resource.
|
|
30
|
+
# @parameter concurrency [Integer] The maximum number of concurrent tasks that can be creating a new resource. Defaults to 1 to ensure the pool limit is enforced. Higher values may result in more resources being created than the limit under high load.
|
|
30
31
|
# @parameter policy [Policy] The pool policy.
|
|
31
|
-
def initialize(constructor, limit: nil, concurrency:
|
|
32
|
+
def initialize(constructor, limit: nil, concurrency: 1, policy: nil, tags: nil)
|
|
32
33
|
@constructor = constructor
|
|
33
34
|
@limit = limit
|
|
34
35
|
|
|
@@ -232,13 +233,13 @@ module Async
|
|
|
232
233
|
|
|
233
234
|
# Retire a specific resource.
|
|
234
235
|
def retire(resource)
|
|
235
|
-
Console.debug(self)
|
|
236
|
+
Console.debug(self){"Retire #{resource}"}
|
|
236
237
|
|
|
237
|
-
@resources.delete(resource)
|
|
238
|
+
return false unless @resources.delete(resource)
|
|
238
239
|
|
|
239
240
|
resource.close
|
|
240
241
|
|
|
241
|
-
@mutex.synchronize
|
|
242
|
+
@mutex.synchronize{@condition.broadcast}
|
|
242
243
|
|
|
243
244
|
return true
|
|
244
245
|
end
|
|
@@ -254,12 +255,7 @@ module Async
|
|
|
254
255
|
@gardener = task
|
|
255
256
|
|
|
256
257
|
while true
|
|
257
|
-
|
|
258
|
-
@policy.call(self)
|
|
259
|
-
else
|
|
260
|
-
Task.yield
|
|
261
|
-
end
|
|
262
|
-
|
|
258
|
+
@policy&.call(self)
|
|
263
259
|
self.wait
|
|
264
260
|
end
|
|
265
261
|
ensure
|
|
@@ -287,11 +283,15 @@ module Async
|
|
|
287
283
|
# end
|
|
288
284
|
|
|
289
285
|
def reuse(resource)
|
|
290
|
-
Console.debug(self)
|
|
286
|
+
Console.debug(self){"Reuse #{resource}"}
|
|
291
287
|
|
|
292
288
|
usage = @resources[resource]
|
|
293
289
|
|
|
294
|
-
if usage.nil?
|
|
290
|
+
if usage.nil?
|
|
291
|
+
return false
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
if usage.zero?
|
|
295
295
|
raise "Trying to reuse unacquired resource: #{resource}!"
|
|
296
296
|
end
|
|
297
297
|
|
|
@@ -302,7 +302,7 @@ module Async
|
|
|
302
302
|
|
|
303
303
|
@resources[resource] = usage - 1
|
|
304
304
|
|
|
305
|
-
@mutex.synchronize
|
|
305
|
+
@mutex.synchronize{@condition.broadcast}
|
|
306
306
|
|
|
307
307
|
return true
|
|
308
308
|
end
|
|
@@ -310,7 +310,7 @@ module Async
|
|
|
310
310
|
def wait_for_resource
|
|
311
311
|
# If we fail to create a resource (below), we will end up waiting for one to become resources.
|
|
312
312
|
until resource = available_resource
|
|
313
|
-
@mutex.synchronize
|
|
313
|
+
@mutex.synchronize{@condition.wait(@mutex)}
|
|
314
314
|
end
|
|
315
315
|
# Be careful not to context switch or fail here.
|
|
316
316
|
return resource
|
|
@@ -360,7 +360,7 @@ module Async
|
|
|
360
360
|
return resource
|
|
361
361
|
end
|
|
362
362
|
end
|
|
363
|
-
@mutex.synchronize
|
|
363
|
+
@mutex.synchronize{@condition.wait(@mutex)}
|
|
364
364
|
end
|
|
365
365
|
# Only when the pool has been completely drained, return nil:
|
|
366
366
|
return nil
|
|
@@ -389,7 +389,7 @@ module Async
|
|
|
389
389
|
end
|
|
390
390
|
|
|
391
391
|
if @limit.nil? or @resources.size < @limit
|
|
392
|
-
Console.debug(self)
|
|
392
|
+
Console.debug(self){"No available resources, allocating new one..."}
|
|
393
393
|
|
|
394
394
|
return create_resource
|
|
395
395
|
end
|
data/lib/async/pool/version.rb
CHANGED
|
@@ -13,7 +13,7 @@ Traces::Provider(Async::Pool::Controller) do
|
|
|
13
13
|
|
|
14
14
|
attributes.merge!(@tags) if @tags
|
|
15
15
|
|
|
16
|
-
Traces.trace("async.pool.create", attributes: attributes)
|
|
16
|
+
Traces.trace("async.pool.create", attributes: attributes){super}
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def drain(...)
|
|
@@ -23,7 +23,7 @@ Traces::Provider(Async::Pool::Controller) do
|
|
|
23
23
|
|
|
24
24
|
attributes.merge!(@tags) if @tags
|
|
25
25
|
|
|
26
|
-
Traces.trace("async.pool.drain", attributes: attributes)
|
|
26
|
+
Traces.trace("async.pool.drain", attributes: attributes){super}
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def acquire(...)
|
|
@@ -34,7 +34,7 @@ Traces::Provider(Async::Pool::Controller) do
|
|
|
34
34
|
|
|
35
35
|
attributes.merge!(@tags) if @tags
|
|
36
36
|
|
|
37
|
-
Traces.trace("async.pool.acquire", attributes: attributes)
|
|
37
|
+
Traces.trace("async.pool.acquire", attributes: attributes){super}
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def release(...)
|
|
@@ -44,7 +44,7 @@ Traces::Provider(Async::Pool::Controller) do
|
|
|
44
44
|
|
|
45
45
|
attributes.merge!(@tags) if @tags
|
|
46
46
|
|
|
47
|
-
Traces.trace("async.pool.release", attributes: attributes)
|
|
47
|
+
Traces.trace("async.pool.release", attributes: attributes){super}
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
def retire(...)
|
|
@@ -54,6 +54,6 @@ Traces::Provider(Async::Pool::Controller) do
|
|
|
54
54
|
|
|
55
55
|
attributes.merge!(@tags) if @tags
|
|
56
56
|
|
|
57
|
-
Traces.trace("async.pool.retire", attributes: attributes)
|
|
57
|
+
Traces.trace("async.pool.retire", attributes: attributes){super}
|
|
58
58
|
end
|
|
59
59
|
end
|
data/license.md
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
# MIT License
|
|
2
2
|
|
|
3
|
-
Copyright, 2019-
|
|
3
|
+
Copyright, 2019-2026, by Samuel Williams.
|
|
4
4
|
Copyright, 2020, by Simon Perepelitsa.
|
|
5
5
|
Copyright, 2021, by Olle Jonsson.
|
|
6
6
|
Copyright, 2024, by Thomas Morgan.
|
|
7
7
|
Copyright, 2025, by Jean Boussier.
|
|
8
|
+
Copyright, 2026, by William T. Nelson.
|
|
8
9
|
|
|
9
10
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
11
|
of this software and associated documentation files (the "Software"), to deal
|
data/readme.md
CHANGED
data/releases.md
CHANGED
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: async-pool
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.11.
|
|
4
|
+
version: 0.11.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Samuel Williams
|
|
@@ -9,6 +9,7 @@ authors:
|
|
|
9
9
|
- Olle Jonsson
|
|
10
10
|
- Simon Perepelitsa
|
|
11
11
|
- Thomas Morgan
|
|
12
|
+
- William T. Nelson
|
|
12
13
|
bindir: bin
|
|
13
14
|
cert_chain:
|
|
14
15
|
- |
|
|
@@ -89,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
89
90
|
- !ruby/object:Gem::Version
|
|
90
91
|
version: '0'
|
|
91
92
|
requirements: []
|
|
92
|
-
rubygems_version:
|
|
93
|
+
rubygems_version: 4.0.3
|
|
93
94
|
specification_version: 4
|
|
94
95
|
summary: A singleplex and multiplex resource pool for implementing robust clients.
|
|
95
96
|
test_files: []
|
metadata.gz.sig
CHANGED
|
Binary file
|