async 2.35.0 → 2.35.2

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: ad14103d1146e967a38187e2d6d3d64b745b50f2f833b164c151ef53d270673e
4
- data.tar.gz: b34db7f89b4054ed33dfbd22d979060b90d939180cf3014c4aa7a5b8c3f070eb
3
+ metadata.gz: 28fcbed588ccb0c02ebed08bfc2d316b07e34563cb52fc639f33d5146c7ca9bc
4
+ data.tar.gz: b9319321c6acb3a6d48b0e76a2afbc3c017586855c6c842950eb0376db8b1bbb
5
5
  SHA512:
6
- metadata.gz: 9b73a930aa37a5cb7695ca5deb66e181d80bd1b1157fbcbf711f6ff2f288c8b1294f05e32e02b68289608b1948315509c66bc541250cd14a19ed40461e283e99
7
- data.tar.gz: 82cef6a6f824e38cf4cdd24a0a6447394e5c8cb37f1c6ec606433e34aa9bd0d6495f92d3fcc290cf298ed497b3967ab9beac5f60d18849f5bcc04df7bee34a39
6
+ metadata.gz: 689e40bffc89b7bc39c1358ef9ab69b5bd49f5840790ebd8e3ebbcfe09d4edbefcd3813e7d4ab8165783a6613624cb1625921140ecb45c124dafc6b5dc424425
7
+ data.tar.gz: 658be41e0d4d602f3a6167f5c380268eff5000114dd117d0edbe0ba8ddda25061935119f07d2f21e286892f46f33b779c785d9104de5a3f4cea10d661a42e093
checksums.yaml.gz.sig CHANGED
Binary file
data/context/tasks.md CHANGED
@@ -99,8 +99,8 @@ By constructing your program correctly, it's easy to implement concurrent map-re
99
99
  ```ruby
100
100
  Async do
101
101
  # Map (create several concurrent tasks)
102
- users_size = Async {User.size}
103
- posts_size = Async {Post.size}
102
+ users_size = Async{User.size}
103
+ posts_size = Async{Post.size}
104
104
 
105
105
  # Reduce (wait for and merge the results)
106
106
  average = posts_size.wait / users_size.wait
@@ -26,7 +26,7 @@ module Async
26
26
  private_constant :ForkHandler
27
27
 
28
28
  # Hook into Process._fork to handle fork events automatically:
29
- unless (Fiber.const_get(:SCHEDULER_PROCESS_FORK) rescue false)
29
+ unless RUBY_VERSION > "4"
30
30
  ::Process.singleton_class.prepend(ForkHandler)
31
31
  end
32
32
  end
data/lib/async/promise.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2025, by Shopify Inc.
5
- # Copyright, 2025, by Samuel Williams.
5
+ # Copyright, 2025-2026, by Samuel Williams.
6
6
 
7
7
  module Async
8
8
  # A promise represents a value that will be available in the future.
@@ -86,7 +86,9 @@ module Async
86
86
 
87
87
  begin
88
88
  # Wait for resolution if not already resolved:
89
- @condition.wait(@mutex) unless @resolved
89
+ until @resolved
90
+ @condition.wait(@mutex)
91
+ end
90
92
 
91
93
  # Return value or raise exception based on resolution type:
92
94
  if @resolved == :completed
@@ -646,17 +646,13 @@ module Async
646
646
  end
647
647
  end
648
648
 
649
- # Handle fork in the child process. This method is called automatically when `Process.fork` is invoked.
649
+ # Handle fork in the child process. This method is called automatically when `Process.fork` is invoked on Ruby versions < 4 and cleans up the scheduler state. On Ruby 4+, the scheduler is automatically cleaned up by the Ruby runtime.
650
650
  #
651
651
  # The child process starts with a clean slate - no scheduler is set. Users can create a new scheduler if needed.
652
652
  #
653
653
  # @public Since *Async v2.35*.
654
654
  def process_fork
655
- if profiler = @profiler
656
- @profiler = nil
657
- profiler.stop
658
- end
659
-
655
+ @profiler = nil
660
656
  @children = nil
661
657
  @selector = nil
662
658
  @timers = nil
data/lib/async/task.rb CHANGED
@@ -61,8 +61,6 @@ module Async
61
61
  # @parameter reactor [Reactor] the reactor this task will run within.
62
62
  # @parameter parent [Task] the parent task.
63
63
  def initialize(parent = Task.current?, finished: nil, **options, &block)
64
- super(parent, **options)
65
-
66
64
  # These instance variables are critical to the state of the task.
67
65
  # In the initialized state, the @block should be set, but the @fiber should be nil.
68
66
  # In the running state, the @fiber should be set, and @block should be nil.
@@ -85,6 +83,9 @@ module Async
85
83
  end
86
84
 
87
85
  @defer_stop = nil
86
+
87
+ # Call this after all state is initialized, as it may call `add_child` which will set the parent and make it visible to the scheduler.
88
+ super(parent, **options)
88
89
  end
89
90
 
90
91
  # @returns [Scheduler] The scheduler for this task.
@@ -265,7 +266,8 @@ module Async
265
266
  # Access the result of the task without waiting. May be nil if the task is not completed. Does not raise exceptions.
266
267
  def result
267
268
  value = @promise.value
268
- # For backward compatibility, return nil for stopped tasks
269
+
270
+ # For backward compatibility, return nil for stopped tasks:
269
271
  if @promise.cancelled?
270
272
  nil
271
273
  else
@@ -409,20 +411,20 @@ module Async
409
411
  # State transition into the completed state.
410
412
  def completed!(result)
411
413
  # Resolve the promise with the result:
412
- @promise&.resolve(result)
414
+ @promise.resolve(result)
413
415
  end
414
416
 
415
417
  # State transition into the failed state.
416
418
  def failed!(exception = false)
417
419
  # Reject the promise with the exception:
418
- @promise&.reject(exception)
420
+ @promise.reject(exception)
419
421
  end
420
422
 
421
423
  def stopped!
422
424
  # Console.info(self, status:) {"Task #{self} was stopped with #{@children&.size.inspect} children!"}
423
425
 
424
426
  # Cancel the promise:
425
- @promise&.cancel
427
+ @promise.cancel
426
428
 
427
429
  stopped = false
428
430
 
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.0"
7
+ VERSION = "2.35.2"
8
8
  end
data/license.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
 
3
- Copyright, 2017-2025, by Samuel Williams.
3
+ Copyright, 2017-2026, by Samuel Williams.
4
4
  Copyright, 2017, by Kent Gruber.
5
5
  Copyright, 2017, by Devin Christensen.
6
6
  Copyright, 2018, by Sokolov Yura.
data/readme.md CHANGED
@@ -35,6 +35,15 @@ 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.35.2
39
+
40
+ - Improved handling of `Process.fork` on Ruby 4+.
41
+ - Improve `@promise` state handling in `Task#initialize`, preventing incomplete instances being visible to the scheduler.
42
+
43
+ ### v2.35.1
44
+
45
+ - Fix incorrect handling of spurious wakeups in `Async::Promise#wait`, which could lead to premature (incorrect) resolution of the promise.
46
+
38
47
  ### v2.35.0
39
48
 
40
49
  - `Process.fork` is now properly handled by the Async fiber scheduler, ensuring that the scheduler state is correctly reset in the child process after a fork. This prevents issues where the child process inherits the scheduler state from the parent, which could lead to unexpected behavior.
@@ -76,14 +85,6 @@ This release introduces thread-safety as a core concept of Async. Many core clas
76
85
  - [Introduce `Async::Promise`](https://socketry.github.io/async/releases/index#introduce-async::promise)
77
86
  - [Introduce `Async::PriorityQueue`](https://socketry.github.io/async/releases/index#introduce-async::priorityqueue)
78
87
 
79
- ### v2.28.1
80
-
81
- - Fix race condition between `Async::Barrier#stop` and finish signalling.
82
-
83
- ### v2.28.0
84
-
85
- - Use `Traces.current_context` and `Traces.with_context` for better integration with OpenTelemetry.
86
-
87
88
  ## See Also
88
89
 
89
90
  - [async-http](https://github.com/socketry/async-http) — Asynchronous HTTP client/server.
data/releases.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Releases
2
2
 
3
+ ## v2.35.2
4
+
5
+ - Improved handling of `Process.fork` on Ruby 4+.
6
+ - Improve `@promise` state handling in `Task#initialize`, preventing incomplete instances being visible to the scheduler.
7
+
8
+ ## v2.35.1
9
+
10
+ - Fix incorrect handling of spurious wakeups in `Async::Promise#wait`, which could lead to premature (incorrect) resolution of the promise.
11
+
3
12
  ## v2.35.0
4
13
 
5
14
  - `Process.fork` is now properly handled by the Async fiber scheduler, ensuring that the scheduler state is correctly reset in the child process after a fork. This prevents issues where the child process inherits the scheduler state from the parent, which could lead to unexpected behavior.
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.0
4
+ version: 2.35.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -213,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
213
213
  - !ruby/object:Gem::Version
214
214
  version: '0'
215
215
  requirements: []
216
- rubygems_version: 3.6.9
216
+ rubygems_version: 4.0.3
217
217
  specification_version: 4
218
218
  summary: A concurrency framework for Ruby.
219
219
  test_files: []
metadata.gz.sig CHANGED
Binary file