async 1.31.0 → 1.32.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: f54f8b2dedcd29cf6a5d5c19b9b6ef11762cac77156439930b29d414e45bb6d4
4
- data.tar.gz: c420baf542fe9992737ac9d8594cd3f88bb7764904113d801aa891ec328558ee
3
+ metadata.gz: 0ed31b6b8b115f7013a59e0eb58fd10793c061a8be9968f83fc3d8ee750e92c8
4
+ data.tar.gz: a7517e133ad3f944067399f2b9f9dd3e7753fb82cd4912424dd0690f17eebd3d
5
5
  SHA512:
6
- metadata.gz: ff4f467f2d8f2bde924e29636d8d0689509acfd1d463825173d03aa75b4235847db43c7fc6a9d4a10e18a444d542332218e1f3a9a0bb471d1a918bb411dd7a73
7
- data.tar.gz: 95affc48630a0b2e83457e58024dfa89c091060b1047151849e30bce3a493a5e5ffaa06e824086df347dfb862f66cf834a08f3609d4b718eb7e3c74157bc1ad9
6
+ metadata.gz: 4819e554eec0bc91973791b6d87042638658f54e372ee11f32dd11c7c319d28cf9a08745f7f2a1af04ca0f20cff7a5c29174fcb7fddcc78a56a44f1499385a39
7
+ data.tar.gz: 2e777449edd348c2db0dc0a50d756981cd5e0a2e5d9f709e1f0dbbc609e39e4e840b86258d0a1a744473855cbec8539b3398b91e01133128a84721c77bfc0e6d
data/lib/async/reactor.rb CHANGED
@@ -93,6 +93,10 @@ module Async
93
93
  @unblocked = []
94
94
  end
95
95
 
96
+ def inspect
97
+ "#<#{self.class} children=#{@children&.size} stopped=#{stopped?}>"
98
+ end
99
+
96
100
  attr :scheduler
97
101
  attr :logger
98
102
 
data/lib/async/task.rb CHANGED
@@ -84,6 +84,8 @@ module Async
84
84
  @logger = logger || @parent.logger
85
85
 
86
86
  @fiber = make_fiber(&block)
87
+
88
+ @defer_stop = nil
87
89
  end
88
90
 
89
91
  attr :logger
@@ -162,6 +164,13 @@ module Async
162
164
  return
163
165
  end
164
166
 
167
+ # If we are deferring stop...
168
+ if @defer_stop == false
169
+ # Don't stop now... but update the state so we know we need to stop later.
170
+ @defer_stop = true
171
+ return false
172
+ end
173
+
165
174
  if self.running?
166
175
  if self.current?
167
176
  if later
@@ -182,6 +191,41 @@ module Async
182
191
  end
183
192
  end
184
193
 
194
+ # 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.
195
+ #
196
+ # You can nest calls to defer_stop, but the stop will only be deferred until the outermost block exits.
197
+ #
198
+ # If stop is invoked a second time, it will be immediately executed.
199
+ #
200
+ # @yields {} The block of code to execute.
201
+ def defer_stop
202
+ # Tri-state variable for controlling stop:
203
+ # - nil: defer_stop has not been called.
204
+ # - false: defer_stop has been called and we are not stopping.
205
+ # - true: defer_stop has been called and we will stop when exiting the block.
206
+ if @defer_stop.nil?
207
+ # If we are not deferring stop already, we can defer it now:
208
+ @defer_stop = false
209
+
210
+ begin
211
+ yield
212
+ rescue Stop
213
+ # If we are exiting due to a stop, we shouldn't try to invoke stop again:
214
+ @defer_stop = nil
215
+ raise
216
+ ensure
217
+ # If we were asked to stop, we should do so now:
218
+ if @defer_stop
219
+ @defer_stop = nil
220
+ self.stop
221
+ end
222
+ end
223
+ else
224
+ # If we are deferring stop already, entering it again is a no-op.
225
+ yield
226
+ end
227
+ end
228
+
185
229
  # Lookup the {Task} for the current fiber. Raise `RuntimeError` if none is available.
186
230
  # @return [Async::Task]
187
231
  # @raise [RuntimeError] if task was not {set!} for the current fiber.
data/lib/async/version.rb CHANGED
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Async
24
- VERSION = "1.31.0"
24
+ VERSION = "1.32.1"
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.31.0
4
+ version: 1.32.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-02 00:00:00.000000000 Z
11
+ date: 2024-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: console
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
180
  - !ruby/object:Gem::Version
181
181
  version: '0'
182
182
  requirements: []
183
- rubygems_version: 3.4.7
183
+ rubygems_version: 3.5.3
184
184
  signing_key:
185
185
  specification_version: 4
186
186
  summary: A concurrency framework for Ruby.