async 2.35.3 → 2.36.0

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: 7c439d8ba1591623b695ccd1dd4fe68f822fedd589291a7bdd79a53ce9c430d7
4
- data.tar.gz: cc8902bc5b15f446df404967e1832c9847eb0bcad879565508f6688bd0a5c92a
3
+ metadata.gz: b514097c721290749f38fed73721c5cb6d17af2a8af189f5a8e537f7b30c14d3
4
+ data.tar.gz: 3eba30b0a03bdb9f9da1d1e4eeb6b11ec3224c0f3d02f27cc07ac1e5e7d7a41e
5
5
  SHA512:
6
- metadata.gz: c2bfeb61c9f9ddad7576c66be0b637bee5934159e9388fe21cd0b1e8e5df804b5818194ef812d6249570411591d232a4c570fc6c6bcd02d67496e7aaf8950467
7
- data.tar.gz: 2454b411f93e6e86e25030bdd358eba7ed38536928ab64dc64b1dc10e3dff152ac4005ad27bdf3d4e801c49d69c2b386f7ca08961d90015dbe86fa2e9bccc5cf
6
+ metadata.gz: 9ea8d371279ec9bf8feeaa85895f25733247c8ecb059d599f34e8ecc85b4b124c05dee5421414d28c24316d7c4e69bdff622c31b182e9f883456836a6aab17ed
7
+ data.tar.gz: 55ddefa4f011c2dccf235043cad5ad334418c394ced59a960b993d18ead0850f7d60875a3edbdc55418d3a9d3045cef1d607170fea0ae484f4dc62bc13f15ca2
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/async/node.rb CHANGED
@@ -295,6 +295,12 @@ module Async
295
295
  end
296
296
  end
297
297
 
298
+ # Wait for this node to complete. By default, nodes cannot be waited on.
299
+ # Subclasses like Task override this method to provide waiting functionality.
300
+ def wait
301
+ nil
302
+ end
303
+
298
304
  # Whether the node has been stopped.
299
305
  def stopped?
300
306
  @children.nil?
data/lib/async/task.rb CHANGED
@@ -31,6 +31,32 @@ module Async
31
31
  end
32
32
  end
33
33
 
34
+ # Represents a sequential unit of work, defined by a block, which is executed concurrently with other tasks. A task can be in one of the following states: `initialized`, `running`, `completed`, `failed`, `cancelled` or `stopped`.
35
+ #
36
+ # ```mermaid
37
+ # stateDiagram-v2
38
+ # [*] --> Initialized
39
+ # Initialized --> Running : Run
40
+ #
41
+ # Running --> Completed : Return Value
42
+ # Running --> Failed : Exception
43
+ #
44
+ # Completed --> [*]
45
+ # Failed --> [*]
46
+ #
47
+ # Running --> Stopped : Stop
48
+ # Stopped --> [*]
49
+ # Completed --> Stopped : Stop
50
+ # Failed --> Stopped : Stop
51
+ # Initialized --> Stopped : Stop
52
+ # ```
53
+ #
54
+ # @example Creating a task that sleeps for 1 second.
55
+ # require "async"
56
+ # Async do |task|
57
+ # sleep(1)
58
+ # end
59
+ #
34
60
  # @public Since *Async v1*.
35
61
  class Task < Node
36
62
  # Raised when a child task is created within a task that has finished execution.
@@ -258,11 +284,43 @@ module Async
258
284
  begin
259
285
  @promise.wait
260
286
  rescue Promise::Cancel
261
- # For backward compatibility, stopped tasks return nil
287
+ # For backward compatibility, stopped tasks return nil:
262
288
  return nil
263
289
  end
264
290
  end
265
291
 
292
+ # For compatibility with `Thread#join` and similar interfaces.
293
+ alias join wait
294
+
295
+ # Wait on all non-transient children to complete, recursively, then wait on the task itself, if it is not the current task.
296
+ #
297
+ # If any child task fails with an exception, that exception will be raised immediately, and remaining children may not be waited on.
298
+ #
299
+ # @example Waiting on all children.
300
+ # Async do |task|
301
+ # child = task.async do
302
+ # sleep(0.01)
303
+ # end
304
+ # task.wait_all # Will wait on the child task.
305
+ # end
306
+ #
307
+ # @raises [StandardError] If any child task failed with an exception, that exception will be raised.
308
+ # @returns [Object | Nil] The final expression/result of the task's block, or nil if called from within the task.
309
+ # @asynchronous This method is thread-safe.
310
+ def wait_all
311
+ @children&.each do |child|
312
+ # Skip transient tasks
313
+ next if child.transient?
314
+
315
+ child.wait_all
316
+ end
317
+
318
+ # Only wait on the task if we're not waiting on ourselves:
319
+ unless self.current?
320
+ return self.wait
321
+ end
322
+ end
323
+
266
324
  # Access the result of the task without waiting. May be nil if the task is not completed. Does not raise exceptions.
267
325
  def result
268
326
  value = @promise.value
data/lib/async/version.rb CHANGED
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2017-2025, by Samuel Williams.
5
5
 
6
6
  module Async
7
- VERSION = "2.35.3"
7
+ VERSION = "2.36.0"
8
8
  end
data/readme.md CHANGED
@@ -35,6 +35,11 @@ Please see the [project documentation](https://socketry.github.io/async/) for mo
35
35
 
36
36
  Please see the [project releases](https://socketry.github.io/async/releases/index) for all releases.
37
37
 
38
+ ### v2.36.0
39
+
40
+ - Introduce `Task#wait_all` which recursively waits for all children and self, excepting the current task.
41
+ - Introduce `Task#join` as an alias for `Task#wait` for compatibility with `Thread#join` and similar interfaces.
42
+
38
43
  ### v2.35.3
39
44
 
40
45
  - `Async::Clock` now implements `#as_json` and `#to_json` for nicer log formatting.
@@ -72,13 +77,6 @@ Please see the [project releases](https://socketry.github.io/async/releases/inde
72
77
 
73
78
  - Introduce `Async::Deadline` for precise timeout management in compound operations.
74
79
 
75
- ### v2.30.0
76
-
77
- - Add timeout support to `Async::Queue#dequeue` and `Async::Queue#pop` methods.
78
- - Add timeout support to `Async::PriorityQueue#dequeue` and `Async::PriorityQueue#pop` methods.
79
- - Add `closed?` method to `Async::PriorityQueue` for full queue interface compatibility.
80
- - Support non-blocking operations using `timeout: 0` parameter.
81
-
82
80
  ## See Also
83
81
 
84
82
  - [async-http](https://github.com/socketry/async-http) — Asynchronous HTTP client/server.
data/releases.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Releases
2
2
 
3
+ ## v2.36.0
4
+
5
+ - Introduce `Task#wait_all` which recursively waits for all children and self, excepting the current task.
6
+ - Introduce `Task#join` as an alias for `Task#wait` for compatibility with `Thread#join` and similar interfaces.
7
+
3
8
  ## v2.35.3
4
9
 
5
10
  - `Async::Clock` now implements `#as_json` and `#to_json` for nicer log formatting.
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.35.3
4
+ version: 2.36.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -175,7 +175,6 @@ files:
175
175
  - lib/async/semaphore.md
176
176
  - lib/async/semaphore.rb
177
177
  - lib/async/stop.rb
178
- - lib/async/task.md
179
178
  - lib/async/task.rb
180
179
  - lib/async/timeout.rb
181
180
  - lib/async/variable.rb
metadata.gz.sig CHANGED
Binary file
data/lib/async/task.md DELETED
@@ -1,30 +0,0 @@
1
- A sequence of instructions, defined by a block, which is executed sequentially and managed by the scheduler. A task can be in one of the following states: `initialized`, `running`, `completed`, `failed`, `cancelled` or `stopped`.
2
-
3
- ```mermaid
4
- stateDiagram-v2
5
- [*] --> Initialized
6
- Initialized --> Running : Run
7
-
8
- Running --> Completed : Return Value
9
- Running --> Failed : Exception
10
-
11
- Completed --> [*]
12
- Failed --> [*]
13
-
14
- Running --> Stopped : Stop
15
- Stopped --> [*]
16
- Completed --> Stopped : Stop
17
- Failed --> Stopped : Stop
18
- Initialized --> Stopped : Stop
19
- ```
20
-
21
- ## Example
22
-
23
- ```ruby
24
- require "async"
25
-
26
- # Create an asynchronous task that sleeps for 1 second:
27
- Async do |task|
28
- sleep(1)
29
- end
30
- ```