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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/context/tasks.md +2 -2
- data/lib/async/fork_handler.rb +1 -1
- data/lib/async/promise.rb +4 -2
- data/lib/async/scheduler.rb +2 -6
- data/lib/async/task.rb +8 -6
- data/lib/async/version.rb +1 -1
- data/license.md +1 -1
- data/readme.md +9 -8
- data/releases.md +9 -0
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 28fcbed588ccb0c02ebed08bfc2d316b07e34563cb52fc639f33d5146c7ca9bc
|
|
4
|
+
data.tar.gz: b9319321c6acb3a6d48b0e76a2afbc3c017586855c6c842950eb0376db8b1bbb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
103
|
-
posts_size = Async
|
|
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
|
data/lib/async/fork_handler.rb
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
data/lib/async/scheduler.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
427
|
+
@promise.cancel
|
|
426
428
|
|
|
427
429
|
stopped = false
|
|
428
430
|
|
data/lib/async/version.rb
CHANGED
data/license.md
CHANGED
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.
|
|
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:
|
|
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
|