async-pool 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cfc00b6087965cc5fc3f58ae151a0048fc8cf351aab9c06bdaf46b0eb65bb877
4
- data.tar.gz: 7f9e3067d5bc75de995735ac4a025cb6cea4ee72e0e63201ec4f28c000301cc2
3
+ metadata.gz: eb369c01748a2f2c555a8549a2280c1e39b30a3c7f7918e4e426a79d7eec41ce
4
+ data.tar.gz: 5b8d9ac62de382ce06753d04512708cca9c969c7eaf368a1f7b88fa12b6d1eae
5
5
  SHA512:
6
- metadata.gz: e6933852df812446375faf0c0c921c137bdd972beec9f1e392f6bdfc0c803ddf1cf62151323fbd18f8431c9ab1021eaac2c90ab461f03679d3e93cebfbc039b0
7
- data.tar.gz: 76a83cc5cc6a5dc2230ae6ad3eedc12a0e4fc24170d7391d5a1c032553d4a5653fc89b12060e331bd64687fefb5308d64785bbdc9cc70701b3f86e394de718f2
6
+ metadata.gz: b18bfe389d25644da07f2e8f85bd92891f7066e1c9b67d6ed91e9a9de1e8d47bcaf4e612c7388619a8693c2f6ee2fc85a09f0cada7647f53a2de5714dbaac30a
7
+ data.tar.gz: 0bb8ca350d3942057cfcc91ff957382512ee0e1e012e20344ba71b6bf09df7a353c65d4996341fc8407d99629a8286346a6412a4e6bc6a0199dcaf67e11d069f
checksums.yaml.gz.sig CHANGED
Binary file
@@ -154,20 +154,18 @@ module Async
154
154
  retire(resource) unless processed
155
155
  end
156
156
 
157
+ private def drain
158
+ # Enumerate all existing resources and retire them:
159
+ while resource = acquire_existing_resource
160
+ retire(resource)
161
+ end
162
+ end
163
+
157
164
  # Close all resources in the pool.
158
165
  def close
159
- @available.clear
160
-
161
- while pair = @resources.shift
162
- resource, usage = pair
163
-
164
- if usage > 0
165
- Console.warn(self, resource: resource, usage: usage) {"Closing resource while still in use!"}
166
- end
167
-
168
- resource.close
169
- end
166
+ self.drain
170
167
 
168
+ @available.clear
171
169
  @gardener&.stop
172
170
  end
173
171
 
@@ -224,6 +222,8 @@ module Async
224
222
  def start_gardener
225
223
  return if @gardener
226
224
 
225
+ @gardener = true
226
+
227
227
  Async(transient: true, annotation: "#{self.class} Gardener") do |task|
228
228
  @gardener = task
229
229
 
@@ -319,7 +319,7 @@ module Async
319
319
  resource = nil
320
320
 
321
321
  @guard.acquire do
322
- resource = get_resource
322
+ resource = acquire_or_create_resource
323
323
  end
324
324
 
325
325
  return resource
@@ -330,7 +330,24 @@ module Async
330
330
 
331
331
  private
332
332
 
333
- def get_resource
333
+ # Acquire an existing resource with zero usage.
334
+ # If there are resources that are in use, wait until they are released.
335
+ def acquire_existing_resource
336
+ while @resources.any?
337
+ @resources.each do |resource, usage|
338
+ if usage == 0
339
+ return resource
340
+ end
341
+ end
342
+
343
+ @notification.wait
344
+ end
345
+
346
+ # Only when the pool has been completely drained, return nil:
347
+ return nil
348
+ end
349
+
350
+ def acquire_or_create_resource
334
351
  while resource = @available.last
335
352
  if usage = @resources[resource] and usage < resource.concurrency
336
353
  if resource.viable?
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Async
7
7
  module Pool
8
- VERSION = "0.7.1"
8
+ VERSION = "0.8.0"
9
9
  end
10
10
  end
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.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -40,7 +40,7 @@ cert_chain:
40
40
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
41
41
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
42
42
  -----END CERTIFICATE-----
43
- date: 2024-08-03 00:00:00.000000000 Z
43
+ date: 2024-08-07 00:00:00.000000000 Z
44
44
  dependencies:
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: async
metadata.gz.sig CHANGED
Binary file