async 2.17.0 → 2.32.0
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/best-practices.md +188 -0
- data/context/debugging.md +63 -0
- data/context/getting-started.md +177 -0
- data/context/index.yaml +29 -0
- data/context/scheduler.md +109 -0
- data/context/tasks.md +448 -0
- data/context/thread-safety.md +651 -0
- data/lib/async/barrier.md +1 -2
- data/lib/async/barrier.rb +35 -12
- data/lib/async/clock.rb +11 -2
- data/lib/async/condition.md +1 -1
- data/lib/async/condition.rb +18 -34
- data/lib/async/console.rb +42 -0
- data/lib/async/deadline.rb +70 -0
- data/lib/async/idler.rb +2 -1
- data/lib/async/limited_queue.rb +13 -0
- data/lib/async/list.rb +16 -8
- data/lib/async/node.rb +5 -3
- data/lib/async/notification.rb +13 -9
- data/lib/async/priority_queue.rb +253 -0
- data/lib/async/promise.rb +188 -0
- data/lib/async/queue.rb +70 -82
- data/lib/async/reactor.rb +4 -2
- data/lib/async/scheduler.rb +233 -54
- data/lib/async/semaphore.rb +3 -3
- data/lib/async/stop.rb +82 -0
- data/lib/async/task.rb +111 -81
- data/lib/async/timeout.rb +88 -0
- data/lib/async/variable.rb +15 -4
- data/lib/async/version.rb +2 -2
- data/lib/async/waiter.rb +6 -1
- data/lib/kernel/async.rb +1 -1
- data/lib/kernel/sync.rb +14 -5
- data/lib/metrics/provider/async/task.rb +20 -0
- data/lib/metrics/provider/async.rb +6 -0
- data/lib/traces/provider/async/barrier.rb +17 -0
- data/lib/traces/provider/async/task.rb +40 -0
- data/lib/traces/provider/async.rb +7 -0
- data/license.md +8 -1
- data/readme.md +50 -7
- data/releases.md +357 -0
- data.tar.gz.sig +0 -0
- metadata +61 -20
- metadata.gz.sig +0 -0
- data/lib/async/waiter.md +0 -50
- data/lib/async/wrapper.rb +0 -65
metadata
CHANGED
@@ -1,37 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.32.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
|
+
- Shopify Inc.
|
8
9
|
- Bruno Sutic
|
9
10
|
- Jeremy Jung
|
10
11
|
- Olle Jonsson
|
11
|
-
- Devin Christensen
|
12
12
|
- Patrik Wenger
|
13
|
+
- Devin Christensen
|
13
14
|
- Emil Tin
|
14
15
|
- Jamie McCarthy
|
15
16
|
- Kent Gruber
|
17
|
+
- Alan Wu
|
16
18
|
- Brian Morearty
|
17
19
|
- Colin Kelley
|
18
20
|
- Dimitar Peychinov
|
19
21
|
- Gert Goet
|
22
|
+
- Jahfer Husain
|
23
|
+
- Jatin Goyal
|
20
24
|
- Jiang Jinyang
|
25
|
+
- Josh Teeter
|
21
26
|
- Julien Portalier
|
22
27
|
- Jun Jiang
|
23
28
|
- Ken Muryoi
|
24
29
|
- Leon Löchner
|
30
|
+
- Mark Montroy
|
25
31
|
- Masafumi Okura
|
26
32
|
- Masayuki Yamamoto
|
27
33
|
- Math Ieu
|
28
34
|
- Ryan Musgrave
|
29
35
|
- Salim Semaoune
|
30
36
|
- Shannon Skipper
|
37
|
+
- Shigeru Nakajima
|
31
38
|
- Sokolov Yura
|
32
39
|
- Stefan Wrobel
|
33
40
|
- Trevor Turk
|
34
|
-
autorequire:
|
35
41
|
bindir: bin
|
36
42
|
cert_chain:
|
37
43
|
- |
|
@@ -63,7 +69,7 @@ cert_chain:
|
|
63
69
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
64
70
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
65
71
|
-----END CERTIFICATE-----
|
66
|
-
date:
|
72
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
67
73
|
dependencies:
|
68
74
|
- !ruby/object:Gem::Dependency
|
69
75
|
name: console
|
@@ -71,14 +77,14 @@ dependencies:
|
|
71
77
|
requirements:
|
72
78
|
- - "~>"
|
73
79
|
- !ruby/object:Gem::Version
|
74
|
-
version: '1.
|
80
|
+
version: '1.29'
|
75
81
|
type: :runtime
|
76
82
|
prerelease: false
|
77
83
|
version_requirements: !ruby/object:Gem::Requirement
|
78
84
|
requirements:
|
79
85
|
- - "~>"
|
80
86
|
- !ruby/object:Gem::Version
|
81
|
-
version: '1.
|
87
|
+
version: '1.29'
|
82
88
|
- !ruby/object:Gem::Dependency
|
83
89
|
name: fiber-annotation
|
84
90
|
requirement: !ruby/object:Gem::Requirement
|
@@ -99,50 +105,87 @@ dependencies:
|
|
99
105
|
requirements:
|
100
106
|
- - "~>"
|
101
107
|
- !ruby/object:Gem::Version
|
102
|
-
version: '1.
|
103
|
-
|
108
|
+
version: '1.11'
|
109
|
+
type: :runtime
|
110
|
+
prerelease: false
|
111
|
+
version_requirements: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '1.11'
|
116
|
+
- !ruby/object:Gem::Dependency
|
117
|
+
name: metrics
|
118
|
+
requirement: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - "~>"
|
104
121
|
- !ruby/object:Gem::Version
|
105
|
-
version:
|
122
|
+
version: '0.12'
|
106
123
|
type: :runtime
|
107
124
|
prerelease: false
|
108
125
|
version_requirements: !ruby/object:Gem::Requirement
|
109
126
|
requirements:
|
110
127
|
- - "~>"
|
111
128
|
- !ruby/object:Gem::Version
|
112
|
-
version: '
|
113
|
-
|
129
|
+
version: '0.12'
|
130
|
+
- !ruby/object:Gem::Dependency
|
131
|
+
name: traces
|
132
|
+
requirement: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - "~>"
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0.18'
|
137
|
+
type: :runtime
|
138
|
+
prerelease: false
|
139
|
+
version_requirements: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - "~>"
|
114
142
|
- !ruby/object:Gem::Version
|
115
|
-
version:
|
116
|
-
description:
|
117
|
-
email:
|
143
|
+
version: '0.18'
|
118
144
|
executables: []
|
119
145
|
extensions: []
|
120
146
|
extra_rdoc_files: []
|
121
147
|
files:
|
148
|
+
- context/best-practices.md
|
149
|
+
- context/debugging.md
|
150
|
+
- context/getting-started.md
|
151
|
+
- context/index.yaml
|
152
|
+
- context/scheduler.md
|
153
|
+
- context/tasks.md
|
154
|
+
- context/thread-safety.md
|
122
155
|
- lib/async.rb
|
123
156
|
- lib/async/barrier.md
|
124
157
|
- lib/async/barrier.rb
|
125
158
|
- lib/async/clock.rb
|
126
159
|
- lib/async/condition.md
|
127
160
|
- lib/async/condition.rb
|
161
|
+
- lib/async/console.rb
|
162
|
+
- lib/async/deadline.rb
|
128
163
|
- lib/async/idler.rb
|
164
|
+
- lib/async/limited_queue.rb
|
129
165
|
- lib/async/list.rb
|
130
166
|
- lib/async/node.rb
|
131
167
|
- lib/async/notification.rb
|
168
|
+
- lib/async/priority_queue.rb
|
169
|
+
- lib/async/promise.rb
|
132
170
|
- lib/async/queue.rb
|
133
171
|
- lib/async/reactor.rb
|
134
172
|
- lib/async/scheduler.rb
|
135
173
|
- lib/async/semaphore.md
|
136
174
|
- lib/async/semaphore.rb
|
175
|
+
- lib/async/stop.rb
|
137
176
|
- lib/async/task.md
|
138
177
|
- lib/async/task.rb
|
178
|
+
- lib/async/timeout.rb
|
139
179
|
- lib/async/variable.rb
|
140
180
|
- lib/async/version.rb
|
141
|
-
- lib/async/waiter.md
|
142
181
|
- lib/async/waiter.rb
|
143
|
-
- lib/async/wrapper.rb
|
144
182
|
- lib/kernel/async.rb
|
145
183
|
- lib/kernel/sync.rb
|
184
|
+
- lib/metrics/provider/async.rb
|
185
|
+
- lib/metrics/provider/async/task.rb
|
186
|
+
- lib/traces/provider/async.rb
|
187
|
+
- lib/traces/provider/async/barrier.rb
|
188
|
+
- lib/traces/provider/async/task.rb
|
146
189
|
- license.md
|
147
190
|
- readme.md
|
148
191
|
- releases.md
|
@@ -153,7 +196,6 @@ metadata:
|
|
153
196
|
documentation_uri: https://socketry.github.io/async/
|
154
197
|
funding_uri: https://github.com/sponsors/ioquatix/
|
155
198
|
source_code_uri: https://github.com/socketry/async.git
|
156
|
-
post_install_message:
|
157
199
|
rdoc_options: []
|
158
200
|
require_paths:
|
159
201
|
- lib
|
@@ -161,15 +203,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
161
203
|
requirements:
|
162
204
|
- - ">="
|
163
205
|
- !ruby/object:Gem::Version
|
164
|
-
version: 3.
|
206
|
+
version: '3.2'
|
165
207
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
208
|
requirements:
|
167
209
|
- - ">="
|
168
210
|
- !ruby/object:Gem::Version
|
169
211
|
version: '0'
|
170
212
|
requirements: []
|
171
|
-
rubygems_version: 3.
|
172
|
-
signing_key:
|
213
|
+
rubygems_version: 3.6.9
|
173
214
|
specification_version: 4
|
174
215
|
summary: A concurrency framework for Ruby.
|
175
216
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|
data/lib/async/waiter.md
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
A synchronization primitive, which allows you to wait for tasks to complete in order of completion. This is useful for implementing a task pool, where you want to wait for the first task to complete, and then cancel the rest.
|
2
|
-
|
3
|
-
If you try to wait for more things than you have added, you will deadlock.
|
4
|
-
|
5
|
-
## Example
|
6
|
-
|
7
|
-
~~~ ruby
|
8
|
-
require 'async'
|
9
|
-
require 'async/semaphore'
|
10
|
-
require 'async/barrier'
|
11
|
-
require 'async/waiter'
|
12
|
-
|
13
|
-
Sync do
|
14
|
-
barrier = Async::Barrier.new
|
15
|
-
waiter = Async::Waiter.new(parent: barrier)
|
16
|
-
semaphore = Async::Semaphore.new(2, parent: waiter)
|
17
|
-
|
18
|
-
# Sleep sort the numbers:
|
19
|
-
generator = Async do
|
20
|
-
while true
|
21
|
-
semaphore.async do |task|
|
22
|
-
number = rand(1..10)
|
23
|
-
sleep(number)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
numbers = []
|
29
|
-
|
30
|
-
4.times do
|
31
|
-
# Wait for all the numbers to be sorted:
|
32
|
-
numbers << waiter.wait
|
33
|
-
end
|
34
|
-
|
35
|
-
# Don't generate any more numbers:
|
36
|
-
generator.stop
|
37
|
-
|
38
|
-
# Stop all tasks which we don't care about:
|
39
|
-
barrier.stop
|
40
|
-
|
41
|
-
Console.info("Smallest", numbers)
|
42
|
-
end
|
43
|
-
~~~
|
44
|
-
|
45
|
-
### Output
|
46
|
-
|
47
|
-
~~~
|
48
|
-
0.0s info: Smallest
|
49
|
-
| [3, 3, 1, 2]
|
50
|
-
~~~
|
data/lib/async/wrapper.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Released under the MIT License.
|
4
|
-
# Copyright, 2017-2024, by Samuel Williams.
|
5
|
-
# Copyright, 2017, by Kent Gruber.
|
6
|
-
|
7
|
-
module Async
|
8
|
-
# Represents an asynchronous IO within a reactor.
|
9
|
-
# @deprecated With no replacement. Prefer native interfaces.
|
10
|
-
class Wrapper
|
11
|
-
# An exception that occurs when the asynchronous operation was cancelled.
|
12
|
-
class Cancelled < StandardError
|
13
|
-
end
|
14
|
-
|
15
|
-
# @parameter io the native object to wrap.
|
16
|
-
# @parameter reactor [Reactor] the reactor that is managing this wrapper, or not specified, it's looked up by way of {Task.current}.
|
17
|
-
def initialize(io, reactor = nil)
|
18
|
-
@io = io
|
19
|
-
@reactor = reactor
|
20
|
-
|
21
|
-
@timeout = nil
|
22
|
-
end
|
23
|
-
|
24
|
-
attr_accessor :reactor
|
25
|
-
|
26
|
-
# Dup the underlying IO.
|
27
|
-
def dup
|
28
|
-
self.class.new(@io.dup)
|
29
|
-
end
|
30
|
-
|
31
|
-
# The underlying native `io`.
|
32
|
-
attr :io
|
33
|
-
|
34
|
-
# Wait for the io to become readable.
|
35
|
-
def wait_readable(timeout = @timeout)
|
36
|
-
@io.to_io.wait_readable(timeout) or raise TimeoutError
|
37
|
-
end
|
38
|
-
|
39
|
-
# Wait for the io to become writable.
|
40
|
-
def wait_priority(timeout = @timeout)
|
41
|
-
@io.to_io.wait_priority(timeout) or raise TimeoutError
|
42
|
-
end
|
43
|
-
|
44
|
-
# Wait for the io to become writable.
|
45
|
-
def wait_writable(timeout = @timeout)
|
46
|
-
@io.to_io.wait_writable(timeout) or raise TimeoutError
|
47
|
-
end
|
48
|
-
|
49
|
-
# Wait fo the io to become either readable or writable.
|
50
|
-
# @parameter duration [Float] timeout after the given duration if not `nil`.
|
51
|
-
def wait_any(timeout = @timeout)
|
52
|
-
@io.to_io.wait(::IO::READABLE|::IO::WRITABLE|::IO::PRIORITY, timeout) or raise TimeoutError
|
53
|
-
end
|
54
|
-
|
55
|
-
# Close the underlying IO.
|
56
|
-
def close
|
57
|
-
@io.close
|
58
|
-
end
|
59
|
-
|
60
|
-
# Whether the underlying IO is closed.
|
61
|
-
def closed?
|
62
|
-
@io.closed?
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|