async 2.38.0 → 2.38.1

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: 847417a49140235dad0d6e2b063dd6a3465247cb7b3000708d58bd01adbcffb1
4
- data.tar.gz: f79a5b29cd8e10bdfe7f10ba24f0fb850bb0856e8612dffcecdd7882c133bc61
3
+ metadata.gz: 775f7308b78b3544dca24cb0db4c79bbb952fc6446c25bb77e8edb78ece4a090
4
+ data.tar.gz: dfbb05706b19dd0b47269d73dc6acb28194ef9ff4b9ce6c9d7e19eb30ccf9170
5
5
  SHA512:
6
- metadata.gz: c0b69a0ff96474b52956268018bf8a08aa147aff8c0c80c60185cd070f7d3d36360f3b9f2f8ae1d082a0ee8d4fc172621323bd1e99de5a8ea946f7263761e120
7
- data.tar.gz: 80c5f6e6e946b3675ad55cc40ae30ff860aeb08dd732a5d87e2350a4c6ac48d6619c434900e39f9012a76d398930debb56c8d183ef9e139a62138b060a0b24bc
6
+ metadata.gz: 02f8bb5e3e57798f7af1901ea1b6fdab323a957634f2b8bb644cc5942dc32d5808cbce18eb68953ba6e2e764c861c040705821e690ae3dd09f902f5d9e25e3b5
7
+ data.tar.gz: fe7e1c8fc1d166a6d8c55b1c1fb56645db4b742c9203392b6fb668ca58d50d65303f2998077363a83078f2ab0fd9429d097ea86d8013eb22a43eb2a275262305
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/async/barrier.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2019-2026, by Samuel Williams.
5
+ # Copyright, 2026, by Tavian Barnes.
5
6
 
6
7
  require_relative "list"
7
8
  require_relative "task"
@@ -18,6 +19,7 @@ module Async
18
19
  def initialize(parent: nil)
19
20
  @tasks = List.new
20
21
  @finished = Queue.new
22
+ @condition = Condition.new
21
23
 
22
24
  @parent = parent
23
25
  end
@@ -42,18 +44,32 @@ module Async
42
44
 
43
45
  # Execute a child task and add it to the barrier.
44
46
  # @asynchronous Executes the given block concurrently.
47
+ # @returns [Task] The task which was created to execute the block.
45
48
  def async(*arguments, parent: (@parent or Task.current), **options, &block)
46
49
  raise "Barrier is stopped!" if @finished.closed?
47
50
 
48
51
  waiting = nil
49
52
 
50
- parent.async(*arguments, **options) do |task, *arguments|
51
- waiting = TaskNode.new(task)
52
- @tasks.append(waiting)
53
+ task = parent.async(*arguments, **options) do |task, *arguments|
54
+ # Create a new list node for the task and add it to the list of waiting tasks:
55
+ node = TaskNode.new(task)
56
+ @tasks.append(node)
57
+
58
+ # Signal the outer async block that we have added the task to the list of waiting tasks, and that it can now wait for it to finish:
59
+ waiting = node
60
+ @condition.signal
61
+
62
+ # Invoke the block, which may raise an error. If it does, we will still signal that the task has finished:
53
63
  block.call(task, *arguments)
54
64
  ensure
55
- @finished.signal(waiting) unless @finished.closed?
65
+ # Signal that the task has finished, which will unblock the waiting task:
66
+ @finished.signal(node) unless @finished.closed?
56
67
  end
68
+
69
+ # `parent.async` may yield before the child block executes, so we wait here until the child has appended itself to `@tasks`, ensuring `wait` cannot return early and miss tracking it:
70
+ @condition.wait while waiting.nil?
71
+
72
+ return task
57
73
  end
58
74
 
59
75
  # Whether there are any tasks being held by the barrier.
data/lib/async/version.rb CHANGED
@@ -5,5 +5,5 @@
5
5
 
6
6
  # @namespace
7
7
  module Async
8
- VERSION = "2.38.0"
8
+ VERSION = "2.38.1"
9
9
  end
data/license.md CHANGED
@@ -35,6 +35,7 @@ Copyright, 2025-2026, by Shopify Inc.
35
35
  Copyright, 2025, by Josh Teeter.
36
36
  Copyright, 2025, by Jatin Goyal.
37
37
  Copyright, 2025, by Yuhi Sato.
38
+ Copyright, 2026, by Tavian Barnes.
38
39
 
39
40
  Permission is hereby granted, free of charge, to any person obtaining a copy
40
41
  of this software and associated documentation files (the "Software"), to deal
data/readme.md CHANGED
@@ -35,6 +35,10 @@ 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.38.1
39
+
40
+ - Fix `Barrier#async` when `parent.async` yields before the child block executes. Previously, `Barrier#wait` could return early and miss tracking the task entirely, because the task had not yet appended itself to the barrier's task list.
41
+
38
42
  ### v2.38.0
39
43
 
40
44
  - Rename `Task#stop` to `Task#cancel` for better clarity and consistency with common concurrency terminology. The old `stop` method is still available as an alias for backward compatibility, but it is recommended to use `cancel` going forward.
@@ -75,10 +79,6 @@ Please see the [project releases](https://socketry.github.io/async/releases/inde
75
79
 
76
80
  - Introduce `Async::Promise.fulfill` for optional promise resolution.
77
81
 
78
- ### v2.32.1
79
-
80
- - Fix typo in documentation.
81
-
82
82
  ## See Also
83
83
 
84
84
  - [async-http](https://github.com/socketry/async-http) — Asynchronous HTTP client/server.
data/releases.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Releases
2
2
 
3
+ ## v2.38.1
4
+
5
+ - Fix `Barrier#async` when `parent.async` yields before the child block executes. Previously, `Barrier#wait` could return early and miss tracking the task entirely, because the task had not yet appended itself to the barrier's task list.
6
+
3
7
  ## v2.38.0
4
8
 
5
9
  - Rename `Task#stop` to `Task#cancel` for better clarity and consistency with common concurrency terminology. The old `stop` method is still available as an alias for backward compatibility, but it is recommended to use `cancel` going forward.
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.38.0
4
+ version: 2.38.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -37,6 +37,7 @@ authors:
37
37
  - Shigeru Nakajima
38
38
  - Sokolov Yura
39
39
  - Stefan Wrobel
40
+ - Tavian Barnes
40
41
  - Trevor Turk
41
42
  - Yuhi Sato
42
43
  bindir: bin
metadata.gz.sig CHANGED
Binary file