async 1.30.0 → 2.0.1
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
- data/lib/async/barrier.md +36 -0
- data/lib/async/barrier.rb +27 -7
- data/lib/async/clock.rb +11 -0
- data/lib/async/condition.md +31 -0
- data/lib/async/condition.rb +27 -17
- data/lib/async/node.rb +28 -13
- data/lib/async/notification.rb +4 -4
- data/lib/async/queue.rb +6 -2
- data/lib/async/reactor.rb +10 -316
- data/lib/async/scheduler.rb +241 -48
- data/lib/async/semaphore.md +41 -0
- data/lib/async/semaphore.rb +8 -5
- data/lib/async/task.rb +59 -60
- data/lib/async/{logger.rb → variable.rb} +30 -3
- data/lib/async/version.rb +1 -1
- data/lib/async/wrapper.rb +19 -179
- data/lib/async.rb +0 -5
- data/lib/kernel/async.rb +26 -2
- data/lib/kernel/sync.rb +14 -4
- metadata +28 -10
- data/lib/async/debug/monitor.rb +0 -47
- data/lib/async/debug/selector.rb +0 -82
data/lib/kernel/sync.rb
CHANGED
|
@@ -22,16 +22,26 @@
|
|
|
22
22
|
|
|
23
23
|
require_relative "../async/reactor"
|
|
24
24
|
|
|
25
|
+
# Extensions to all Ruby objects.
|
|
25
26
|
module Kernel
|
|
26
27
|
# Run the given block of code synchronously, but within a reactor if not already in one.
|
|
28
|
+
#
|
|
29
|
+
# @yields {|task| ...} The block that will execute asynchronously.
|
|
30
|
+
# @parameter task [Async::Task] The task that is executing the given block.
|
|
31
|
+
#
|
|
32
|
+
# @public Since `stable-v1`.
|
|
33
|
+
# @asynchronous Will block until given block completes executing.
|
|
27
34
|
def Sync(&block)
|
|
28
35
|
if task = ::Async::Task.current?
|
|
29
36
|
yield task
|
|
30
37
|
else
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
38
|
+
reactor = Async::Reactor.new
|
|
39
|
+
|
|
40
|
+
begin
|
|
41
|
+
return reactor.run(finished: ::Async::Condition.new, &block).wait
|
|
42
|
+
ensure
|
|
43
|
+
Fiber.set_scheduler(nil)
|
|
44
|
+
end
|
|
35
45
|
end
|
|
36
46
|
end
|
|
37
47
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,31 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: async
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Samuel Williams
|
|
8
|
+
- Devin Christensen
|
|
9
|
+
- Bruno Sutic
|
|
10
|
+
- Jeremy Jung
|
|
11
|
+
- Kent Gruber
|
|
12
|
+
- jeremyjung
|
|
13
|
+
- Brian Morearty
|
|
14
|
+
- Jiang Jinyang
|
|
15
|
+
- Julien Portalier
|
|
16
|
+
- Olle Jonsson
|
|
17
|
+
- Patrik Wenger
|
|
18
|
+
- Ryan Musgrave
|
|
19
|
+
- Salim Semaoune
|
|
20
|
+
- Shannon Skipper
|
|
21
|
+
- Sokolov Yura aka funny_falcon
|
|
22
|
+
- Stefan Wrobel
|
|
23
|
+
- jasl
|
|
24
|
+
- muryoimpl
|
|
8
25
|
autorequire:
|
|
9
26
|
bindir: bin
|
|
10
27
|
cert_chain: []
|
|
11
|
-
date:
|
|
28
|
+
date: 2022-03-13 00:00:00.000000000 Z
|
|
12
29
|
dependencies:
|
|
13
30
|
- !ruby/object:Gem::Dependency
|
|
14
31
|
name: console
|
|
@@ -25,19 +42,19 @@ dependencies:
|
|
|
25
42
|
- !ruby/object:Gem::Version
|
|
26
43
|
version: '1.10'
|
|
27
44
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
45
|
+
name: io-event
|
|
29
46
|
requirement: !ruby/object:Gem::Requirement
|
|
30
47
|
requirements:
|
|
31
48
|
- - "~>"
|
|
32
49
|
- !ruby/object:Gem::Version
|
|
33
|
-
version:
|
|
50
|
+
version: 1.0.0
|
|
34
51
|
type: :runtime
|
|
35
52
|
prerelease: false
|
|
36
53
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
54
|
requirements:
|
|
38
55
|
- - "~>"
|
|
39
56
|
- !ruby/object:Gem::Version
|
|
40
|
-
version:
|
|
57
|
+
version: 1.0.0
|
|
41
58
|
- !ruby/object:Gem::Dependency
|
|
42
59
|
name: timers
|
|
43
60
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -143,19 +160,20 @@ extensions: []
|
|
|
143
160
|
extra_rdoc_files: []
|
|
144
161
|
files:
|
|
145
162
|
- lib/async.rb
|
|
163
|
+
- lib/async/barrier.md
|
|
146
164
|
- lib/async/barrier.rb
|
|
147
165
|
- lib/async/clock.rb
|
|
166
|
+
- lib/async/condition.md
|
|
148
167
|
- lib/async/condition.rb
|
|
149
|
-
- lib/async/debug/monitor.rb
|
|
150
|
-
- lib/async/debug/selector.rb
|
|
151
|
-
- lib/async/logger.rb
|
|
152
168
|
- lib/async/node.rb
|
|
153
169
|
- lib/async/notification.rb
|
|
154
170
|
- lib/async/queue.rb
|
|
155
171
|
- lib/async/reactor.rb
|
|
156
172
|
- lib/async/scheduler.rb
|
|
173
|
+
- lib/async/semaphore.md
|
|
157
174
|
- lib/async/semaphore.rb
|
|
158
175
|
- lib/async/task.rb
|
|
176
|
+
- lib/async/variable.rb
|
|
159
177
|
- lib/async/version.rb
|
|
160
178
|
- lib/async/wrapper.rb
|
|
161
179
|
- lib/kernel/async.rb
|
|
@@ -172,14 +190,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
172
190
|
requirements:
|
|
173
191
|
- - ">="
|
|
174
192
|
- !ruby/object:Gem::Version
|
|
175
|
-
version:
|
|
193
|
+
version: 3.1.1
|
|
176
194
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
195
|
requirements:
|
|
178
196
|
- - ">="
|
|
179
197
|
- !ruby/object:Gem::Version
|
|
180
198
|
version: '0'
|
|
181
199
|
requirements: []
|
|
182
|
-
rubygems_version: 3.
|
|
200
|
+
rubygems_version: 3.3.8
|
|
183
201
|
signing_key:
|
|
184
202
|
specification_version: 4
|
|
185
203
|
summary: A concurrency framework for Ruby.
|
data/lib/async/debug/monitor.rb
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
|
4
|
-
#
|
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
|
13
|
-
# all copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
# THE SOFTWARE.
|
|
22
|
-
|
|
23
|
-
require 'delegate'
|
|
24
|
-
|
|
25
|
-
module Async
|
|
26
|
-
module Debug
|
|
27
|
-
class Monitor < Delegator
|
|
28
|
-
def initialize(monitor, selector)
|
|
29
|
-
@monitor = monitor
|
|
30
|
-
@selector = selector
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def __getobj__
|
|
34
|
-
@monitor
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def close
|
|
38
|
-
@selector.deregister(self)
|
|
39
|
-
@monitor.close
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def inspect
|
|
43
|
-
"\#<#{self.class} io=#{@monitor.io.inspect} interests=#{@monitor.interests.inspect} readiness=#{@monitor.readiness.inspect}>"
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
data/lib/async/debug/selector.rb
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
|
4
|
-
#
|
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
|
13
|
-
# all copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
# THE SOFTWARE.
|
|
22
|
-
|
|
23
|
-
require_relative 'monitor'
|
|
24
|
-
require_relative '../logger'
|
|
25
|
-
|
|
26
|
-
require 'nio'
|
|
27
|
-
require 'set'
|
|
28
|
-
|
|
29
|
-
module Async
|
|
30
|
-
module Debug
|
|
31
|
-
class LeakError < RuntimeError
|
|
32
|
-
def initialize(monitors)
|
|
33
|
-
super "Trying to close selector with active monitors: #{monitors.inspect}! This may cause your socket or file descriptor to leak."
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
class Selector
|
|
38
|
-
def initialize(selector = NIO::Selector.new)
|
|
39
|
-
@selector = selector
|
|
40
|
-
@monitors = Set.new
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def register(object, interests)
|
|
44
|
-
Async.logger.debug(self) {"Registering #{object.inspect} for #{interests}."}
|
|
45
|
-
|
|
46
|
-
unless io = ::IO.try_convert(object)
|
|
47
|
-
raise RuntimeError, "Could not convert #{io} into IO!"
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
monitor = Monitor.new(@selector.register(object, interests), self)
|
|
51
|
-
|
|
52
|
-
@monitors.add(monitor)
|
|
53
|
-
|
|
54
|
-
return monitor
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def deregister(monitor)
|
|
58
|
-
Async.logger.debug(self) {"Deregistering #{monitor.inspect}."}
|
|
59
|
-
|
|
60
|
-
unless @monitors.delete?(monitor)
|
|
61
|
-
raise RuntimeError, "Trying to remove monitor for #{monitor.inspect} but it was not registered!"
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def wakeup
|
|
66
|
-
@selector.wakeup
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def close
|
|
70
|
-
if @monitors.any?
|
|
71
|
-
raise LeakError, @monitors
|
|
72
|
-
end
|
|
73
|
-
ensure
|
|
74
|
-
@selector.close
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def select(*arguments)
|
|
78
|
-
@selector.select(*arguments)
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|