async 2.15.3 → 2.16.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f7830bab72d5bdd68def8fe84b914785f191e29dc3f2d0b8f6d58d91878ff72d
4
- data.tar.gz: c54b09d668152d3183ab8b366b75cc09c0e441a54914540896326e87b09a5fe7
3
+ metadata.gz: c003b6b9a92bec85e7bae4b92956e62a0b71d7c862b0c31c4433384bdc72c8fc
4
+ data.tar.gz: 4b401c016afe3359d1d5807194705e553e55550fb7387c0cba25dab4cbc0ba38
5
5
  SHA512:
6
- metadata.gz: 512e6fd4c720c19817bc95db9a7eb85f710314834cc655c9c1e43bac98831aab0802f9ef568de8e2308d1bb0a0304d6f3f4e2e8a465561ec20f79ac2644246d8
7
- data.tar.gz: a0b8dae781660179da1a6ca0b766cbfdba8089684931cc95ea17e1dbf17667b96b34386e50fdceea97768af511dbbc6bbf90140c1027f53adc4db0a81e7d23bc
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.
@@ -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 value
46
+ def wait
45
47
  @condition&.wait
46
48
  return @value
47
49
  end
48
50
 
49
- # Alias for {#value}.
50
- def wait
51
- self.value
52
- end
51
+ alias value wait
53
52
  end
54
53
  end
data/lib/async/version.rb CHANGED
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2017-2024, by Samuel Williams.
5
5
 
6
6
  module Async
7
- VERSION = "2.15.3"
7
+ VERSION = "2.16.0"
8
8
  end
data/lib/kernel/async.rb CHANGED
@@ -24,6 +24,8 @@ module Kernel
24
24
  def Async(...)
25
25
  if current = ::Async::Task.current?
26
26
  return current.async(...)
27
+ elsif scheduler = Fiber.scheduler
28
+ ::Async::Task.run(scheduler, ...)
27
29
  else
28
30
  # This calls Fiber.set_scheduler(self):
29
31
  reactor = ::Async::Reactor.new
data/lib/kernel/sync.rb CHANGED
@@ -18,6 +18,8 @@ module Kernel
18
18
  def Sync(&block)
19
19
  if task = ::Async::Task.current?
20
20
  yield task
21
+ elsif scheduler = Fiber.scheduler
22
+ ::Async::Task.run(scheduler, &block).wait
21
23
  else
22
24
  # This calls Fiber.set_scheduler(self):
23
25
  reactor = Async::Reactor.new
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.15.3
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-08 00:00:00.000000000 Z
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
@@ -167,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
168
  - !ruby/object:Gem::Version
168
169
  version: '0'
169
170
  requirements: []
170
- rubygems_version: 3.5.13
171
+ rubygems_version: 3.5.11
171
172
  signing_key:
172
173
  specification_version: 4
173
174
  summary: A concurrency framework for Ruby.
metadata.gz.sig CHANGED
Binary file