async 2.15.2 → 2.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/async/task.rb +16 -5
- data/lib/async/variable.rb +4 -5
- data/lib/async/version.rb +1 -1
- data/lib/kernel/async.rb +2 -0
- data/lib/kernel/sync.rb +2 -0
- data/readme.md +17 -9
- data/releases.md +24 -0
- data.tar.gz.sig +0 -0
- metadata +3 -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: c003b6b9a92bec85e7bae4b92956e62a0b71d7c862b0c31c4433384bdc72c8fc
|
4
|
+
data.tar.gz: 4b401c016afe3359d1d5807194705e553e55550fb7387c0cba25dab4cbc0ba38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d4d8bcea59a6bb52a94dd80add548354ca2eb4f49e4cf986f45d9a81eea06b39852634b6d699cb387c793f1ad6b14a53f9ef0ccf008df1531f01219937cfe61
|
7
|
+
data.tar.gz: eb67f96629b427458ea68da801e0cbc766dfdf12275c10f130cc14d379e97c369394dfe1d84f6dc33840e928e3d91649225e55716cfb3aa0245e3e6eaa2e1d51
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/async/task.rb
CHANGED
@@ -67,6 +67,13 @@ module Async
|
|
67
67
|
Fiber.scheduler.transfer
|
68
68
|
end
|
69
69
|
|
70
|
+
# Run the given block of code in a task, asynchronously, in the given scheduler.
|
71
|
+
def self.run(scheduler, *arguments, **options, &block)
|
72
|
+
self.new(scheduler, **options, &block).tap do |task|
|
73
|
+
task.run(*arguments)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
70
77
|
# Create a new task.
|
71
78
|
# @parameter reactor [Reactor] the reactor this task will run within.
|
72
79
|
# @parameter parent [Task] the parent task.
|
@@ -304,19 +311,23 @@ module Async
|
|
304
311
|
# - false: defer_stop has been called and we are not stopping.
|
305
312
|
# - true: defer_stop has been called and we will stop when exiting the block.
|
306
313
|
if @defer_stop.nil?
|
307
|
-
# If we are not deferring stop already, we can defer it now:
|
308
|
-
@defer_stop = false
|
309
|
-
|
310
314
|
begin
|
315
|
+
# If we are not deferring stop already, we can defer it now:
|
316
|
+
@defer_stop = false
|
317
|
+
|
311
318
|
yield
|
312
319
|
rescue Stop
|
313
320
|
# If we are exiting due to a stop, we shouldn't try to invoke stop again:
|
314
321
|
@defer_stop = nil
|
315
322
|
raise
|
316
323
|
ensure
|
324
|
+
defer_stop = @defer_stop
|
325
|
+
|
326
|
+
# We need to ensure the state is reset before we exit the block:
|
327
|
+
@defer_stop = nil
|
328
|
+
|
317
329
|
# If we were asked to stop, we should do so now:
|
318
|
-
if
|
319
|
-
@defer_stop = nil
|
330
|
+
if defer_stop
|
320
331
|
raise Stop, "Stopping current task (was deferred)!"
|
321
332
|
end
|
322
333
|
end
|
data/lib/async/variable.rb
CHANGED
@@ -31,6 +31,8 @@ module Async
|
|
31
31
|
condition.signal(value)
|
32
32
|
end
|
33
33
|
|
34
|
+
alias value= resolve
|
35
|
+
|
34
36
|
# Whether the value has been resolved.
|
35
37
|
#
|
36
38
|
# @returns [Boolean] Whether the value has been resolved.
|
@@ -41,14 +43,11 @@ module Async
|
|
41
43
|
# Wait for the value to be resolved.
|
42
44
|
#
|
43
45
|
# @returns [Object] The resolved value.
|
44
|
-
def
|
46
|
+
def wait
|
45
47
|
@condition&.wait
|
46
48
|
return @value
|
47
49
|
end
|
48
50
|
|
49
|
-
|
50
|
-
def wait
|
51
|
-
self.value
|
52
|
-
end
|
51
|
+
alias value wait
|
53
52
|
end
|
54
53
|
end
|
data/lib/async/version.rb
CHANGED
data/lib/kernel/async.rb
CHANGED
data/lib/kernel/sync.rb
CHANGED
data/readme.md
CHANGED
@@ -31,6 +31,23 @@ Please see the [project documentation](https://socketry.github.io/async/) for mo
|
|
31
31
|
|
32
32
|
- [Debugging](https://socketry.github.io/async/guides/debugging/index) - This guide explains how to debug issues with programs that use Async.
|
33
33
|
|
34
|
+
## Releases
|
35
|
+
|
36
|
+
Please see the [project releases](https://socketry.github.io/async/releases/index) for all releases.
|
37
|
+
|
38
|
+
### v2.16.0
|
39
|
+
|
40
|
+
- [Better Handling of Async and Sync in Nested Fibers](https://socketry.github.io/async/releases/index#better-handling-of-async-and-sync-in-nested-fibers)
|
41
|
+
|
42
|
+
## See Also
|
43
|
+
|
44
|
+
- [async-http](https://github.com/socketry/async-http) — Asynchronous HTTP client/server.
|
45
|
+
- [async-websocket](https://github.com/socketry/async-websocket) — Asynchronous client and server websockets.
|
46
|
+
- [async-dns](https://github.com/socketry/async-dns) — Asynchronous DNS resolver and server.
|
47
|
+
- [falcon](https://github.com/socketry/falcon) — A rack compatible server built on top of `async-http`.
|
48
|
+
- [rubydns](https://github.com/ioquatix/rubydns) — An easy to use Ruby DNS server.
|
49
|
+
- [slack-ruby-bot](https://github.com/slack-ruby/slack-ruby-bot) — A client for making slack bots.
|
50
|
+
|
34
51
|
## Contributing
|
35
52
|
|
36
53
|
We welcome contributions to this project.
|
@@ -48,12 +65,3 @@ In order to protect users of this project, we require all contributors to comply
|
|
48
65
|
### Community Guidelines
|
49
66
|
|
50
67
|
This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.
|
51
|
-
|
52
|
-
## See Also
|
53
|
-
|
54
|
-
- [async-http](https://github.com/socketry/async-http) — Asynchronous HTTP client/server.
|
55
|
-
- [async-websocket](https://github.com/socketry/async-websocket) — Asynchronous client and server websockets.
|
56
|
-
- [async-dns](https://github.com/socketry/async-dns) — Asynchronous DNS resolver and server.
|
57
|
-
- [falcon](https://github.com/socketry/falcon) — A rack compatible server built on top of `async-http`.
|
58
|
-
- [rubydns](https://github.com/ioquatix/rubydns) — An easy to use Ruby DNS server.
|
59
|
-
- [slack-ruby-bot](https://github.com/slack-ruby/slack-ruby-bot) — A client for making slack bots.
|
data/releases.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Releases
|
2
|
+
|
3
|
+
## v2.16.0
|
4
|
+
|
5
|
+
### Better Handling of Async and Sync in Nested Fibers
|
6
|
+
|
7
|
+
Interleaving bare fibers within `Async` and `Sync` blocks should not cause problems, but it presents a number of issues in the current implementation. Tracking the parent-child relationship between tasks, when they are interleaved with bare fibers, is difficult. The current implementation assumes that if there is no parent task, then it should create a new reactor. This is not always the case, as the parent task might not be visible due to nested Fibers. As a result, `Async` will create a new reactor, trying to stop the existing one, causing major internal consistency issues.
|
8
|
+
|
9
|
+
I encountered this issue when trying to use `Async` within a streaming response in Rails. The `protocol-rack` [uses a normal fiber to wrap streaming responses](https://github.com/socketry/protocol-rack/blob/cb1ca44e9deadb9369bdb2ea03416556aa927c5c/lib/protocol/rack/body/streaming.rb#L24-L28), and if you try to use `Async` within it, it will create a new reactor, causing the server to lock up.
|
10
|
+
|
11
|
+
Ideally, `Async` and `Sync` helpers should work when any `Fiber.scheduler` is defined. Right now, it's unrealistic to expect `Async::Task` to work in any scheduler, but at the very least, the following should work:
|
12
|
+
|
13
|
+
``` ruby
|
14
|
+
reactor = Async::Reactor.new # internally calls Fiber.set_scheduler
|
15
|
+
|
16
|
+
# This should run in the above reactor, rather than creating a new one.
|
17
|
+
Async do
|
18
|
+
puts "Hello World"
|
19
|
+
end
|
20
|
+
```
|
21
|
+
|
22
|
+
In order to do this, bare `Async` and `Sync` blocks should use `Fiber.scheduler` as a parent if possible.
|
23
|
+
|
24
|
+
See <https://github.com/socketry/async/pull/340> for more details.
|
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.
|
4
|
+
version: 2.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -63,7 +63,7 @@ cert_chain:
|
|
63
63
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
64
64
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
65
65
|
-----END CERTIFICATE-----
|
66
|
-
date: 2024-08-
|
66
|
+
date: 2024-08-23 00:00:00.000000000 Z
|
67
67
|
dependencies:
|
68
68
|
- !ruby/object:Gem::Dependency
|
69
69
|
name: console
|
@@ -145,6 +145,7 @@ files:
|
|
145
145
|
- lib/kernel/sync.rb
|
146
146
|
- license.md
|
147
147
|
- readme.md
|
148
|
+
- releases.md
|
148
149
|
homepage: https://github.com/socketry/async
|
149
150
|
licenses:
|
150
151
|
- MIT
|
metadata.gz.sig
CHANGED
Binary file
|