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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fced21c28680f832d46cd11769b97d5a1dfd7a46761c58a144a1ff5ce178c7ff
4
- data.tar.gz: e23c00cb8b7d48be97f5df59b6f05ea3728b40edbca97cda347740140d77621c
3
+ metadata.gz: e4fe0a9bc65859c5bcb987643f591473236e1fdb2b296c9d73dc9750c01b44ff
4
+ data.tar.gz: 116b1ec100edce9d7bbf85fe57a41d7f7059ed495eca17c8d96940a6c10e7724
5
5
  SHA512:
6
- metadata.gz: a14bbfcb0c1dcd18f044de7caaf901c3ac17d80431342c0e584bd97d311d7d0acb12ec7004f5c0cf4942d406b90a2536ab9bb1297c393b03e3129572b082d342
7
- data.tar.gz: b36b8d19bde4f2503781f828b2a8df3d871915dc852c942658c6779ffa51a0b7e4d29daab077e73a8967f9a2d3734df5437dd433d94aa8c7b9a9a38c4ef4d708
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: (limit || 1), policy: nil, tags: nil)
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) {"Retire #{resource}"}
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 {@condition.broadcast}
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
- if @policy
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) {"Reuse #{resource}"}
286
+ Console.debug(self){"Reuse #{resource}"}
291
287
 
292
288
  usage = @resources[resource]
293
289
 
294
- if usage.nil? || usage.zero?
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 {@condition.broadcast}
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 {@condition.wait(@mutex)}
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 {@condition.wait(@mutex)}
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) {"No available resources, allocating new one..."}
392
+ Console.debug(self){"No available resources, allocating new one..."}
393
393
 
394
394
  return create_resource
395
395
  end
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Async
7
7
  module Pool
8
- VERSION = "0.11.0"
8
+ VERSION = "0.11.2"
9
9
  end
10
10
  end
@@ -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) {super}
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) {super}
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) {super}
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) {super}
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) {super}
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-2025, by Samuel Williams.
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
@@ -14,7 +14,7 @@ Please see the [project documentation](https://socketry.github.io/async-pool/) f
14
14
 
15
15
  Please see the [project releases](https://socketry.github.io/async-pool/releases/index) for all releases.
16
16
 
17
- ### v0.11.0
17
+ ### v0.11.2
18
18
 
19
19
  ## Contributing
20
20
 
data/releases.md CHANGED
@@ -1,3 +1,3 @@
1
1
  # Releases
2
2
 
3
- ## v0.11.0
3
+ ## v0.11.2
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.0
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: 3.6.7
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