async 2.9.0 → 2.10.1

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: e93ed3ea9094d074f430f9518bf0087f57abf732bf196bed5cf8249315aac33d
4
- data.tar.gz: 233dffa50c8bb88cd514545280e3bef088b998a1ddb58e6db68d1a7c8a268c32
3
+ metadata.gz: 80ec5a3027f34138e334db424a42fcf0d424b11d5100527d5e2f8f07534ce33c
4
+ data.tar.gz: 915d39b6b115479c019d8ee0060115d3d1315f8ea864db83887cb158eafe3d2c
5
5
  SHA512:
6
- metadata.gz: bede7ace58ac0e5f6bbefd05a89855a3f80ddf3d02a441aaa73b0a64adeb82b83d02d064121ae267b719519a6fc03f86b7b586f8af3901ae12fcfc6db2d5612c
7
- data.tar.gz: a093ddf356f924089fc8500bee1570cac0e7a4a2e131127eeae0b65813905ae853f44e448f18ecda3d55e39d33f2c7e96c41a34f53cc02259ac8b5bef02e857a
6
+ metadata.gz: 99ae4f68d7aa9ccacc9bb73d80faa687d2c869a61749efadb23bf7f7af1738998f452bccebf18fe2f85af00c456ea31d03cb3e8b822138263064645cd11c1100
7
+ data.tar.gz: 667c747343c640256e6df33bec66a6f05202dd11ed7023e06c8c0b6831c171a468c7558c4d771d644e11765d8071203c1e5f0e490383cdb18269022b39cb7135
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/async/task.rb CHANGED
@@ -67,6 +67,8 @@ module Async
67
67
  @status = :initialized
68
68
  @result = nil
69
69
  @finished = finished
70
+
71
+ @defer_stop = nil
70
72
  end
71
73
 
72
74
  def reactor
@@ -212,6 +214,13 @@ module Async
212
214
  return stopped!
213
215
  end
214
216
 
217
+ # If we are deferring stop...
218
+ if @defer_stop == false
219
+ # Don't stop now... but update the state so we know we need to stop later.
220
+ @defer_stop = true
221
+ return false
222
+ end
223
+
215
224
  # If the fiber is alive, we need to stop it:
216
225
  if @fiber&.alive?
217
226
  if self.current?
@@ -239,6 +248,42 @@ module Async
239
248
  end
240
249
  end
241
250
 
251
+ # Defer the handling of stop. During the execution of the given block, if a stop is requested, it will be deferred until the block exits. This is useful for ensuring graceful shutdown of servers and other long-running tasks. You should wrap the response handling code in a defer_stop block to ensure that the task is stopped when the response is complete but not before.
252
+ #
253
+ # You can nest calls to defer_stop, but the stop will only be deferred until the outermost block exits.
254
+ #
255
+ # If stop is invoked a second time, it will be immediately executed.
256
+ #
257
+ # @yields {} The block of code to execute.
258
+ # @public Since `stable-v1`.
259
+ def defer_stop
260
+ # Tri-state variable for controlling stop:
261
+ # - nil: defer_stop has not been called.
262
+ # - false: defer_stop has been called and we are not stopping.
263
+ # - true: defer_stop has been called and we will stop when exiting the block.
264
+ if @defer_stop.nil?
265
+ # If we are not deferring stop already, we can defer it now:
266
+ @defer_stop = false
267
+
268
+ begin
269
+ yield
270
+ rescue Stop
271
+ # If we are exiting due to a stop, we shouldn't try to invoke stop again:
272
+ @defer_stop = nil
273
+ raise
274
+ ensure
275
+ # If we were asked to stop, we should do so now:
276
+ if @defer_stop
277
+ @defer_stop = nil
278
+ raise Stop, "Stopping current task (was deferred)!"
279
+ end
280
+ end
281
+ else
282
+ # If we are deferring stop already, entering it again is a no-op.
283
+ yield
284
+ end
285
+ end
286
+
242
287
  # Lookup the {Task} for the current fiber. Raise `RuntimeError` if none is available.
243
288
  # @returns [Task]
244
289
  # @raises[RuntimeError] If task was not {set!} for the current fiber.
data/lib/async/version.rb CHANGED
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2017-2024, by Samuel Williams.
5
5
 
6
6
  module Async
7
- VERSION = "2.9.0"
7
+ VERSION = "2.10.1"
8
8
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.0
4
+ version: 2.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -61,7 +61,7 @@ cert_chain:
61
61
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
62
62
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
63
63
  -----END CERTIFICATE-----
64
- date: 2024-03-05 00:00:00.000000000 Z
64
+ date: 2024-03-27 00:00:00.000000000 Z
65
65
  dependencies:
66
66
  - !ruby/object:Gem::Dependency
67
67
  name: console
metadata.gz.sig CHANGED
Binary file