async 1.15.1 → 1.15.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
- data/.travis.yml +3 -0
- data/Gemfile +1 -2
- data/README.md +4 -2
- data/Rakefile +1 -1
- data/async.gemspec +2 -0
- data/lib/async/logger.rb +30 -15
- data/lib/async/version.rb +1 -1
- data/spec/async/condition_spec.rb +1 -0
- data/spec/async/reactor_spec.rb +1 -0
- data/spec/async/task_spec.rb +3 -2
- data/spec/async/wrapper_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -22
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55519b5f7b29512eaceee354a771301269e468d10d18d7e23293eb1338b5f07d
|
4
|
+
data.tar.gz: edddd6b602be01a9bf3cec386746e6de4f95d2f77f614beb1e1e0cb7ae8c615c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 348c0f62da9255a1c05d4c265445657fca1afdddc468fc9308bd1d4c743d70105e34cb8426859da0f59803e360ba545bf554da5019de18031340739a10df8ef9
|
7
|
+
data.tar.gz: 0763a3e5b31f0c9a781598d6cb240aba3c5c282ddbbf68c153adf4e0609ca32ba601b86de0be6bf22b4f5563023cd8a4a82e0645038c75379f87138bbbee988a
|
data/.travis.yml
CHANGED
@@ -11,6 +11,7 @@ before_script:
|
|
11
11
|
- sudo sh -c 'echo 0 > /proc/sys/net/ipv6/conf/all/disable_ipv6'
|
12
12
|
|
13
13
|
after_success:
|
14
|
+
- unset COVERAGE
|
14
15
|
- bundle exec rake external
|
15
16
|
|
16
17
|
matrix:
|
@@ -19,6 +20,8 @@ matrix:
|
|
19
20
|
- rvm: 2.4
|
20
21
|
- rvm: 2.5
|
21
22
|
- rvm: 2.6
|
23
|
+
- rvm: 2.6
|
24
|
+
env: COVERAGE=PartialSummary,Coveralls
|
22
25
|
- rvm: jruby-head
|
23
26
|
env: JRUBY_OPTS="--debug -X+O"
|
24
27
|
- rvm: truffleruby
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -10,6 +10,8 @@ Async is a composable asynchronous I/O framework for Ruby based on [nio4r] and [
|
|
10
10
|
[](https://coveralls.io/r/socketry/async)
|
11
11
|
[](https://gitter.im/socketry/async)
|
12
12
|
|
13
|
+
> "Lately I've been looking into `async`, as one of my projects – [tus-ruby-server](https://github.com/janko/tus-ruby-server) – would really benefit from `async` I/O. It's really beautifully designed." *– [janko](https://github.com/janko)*
|
14
|
+
|
13
15
|
## Motivation
|
14
16
|
|
15
17
|
Several years ago, I was hosting websites on a server in my garage. Back then, my ADSL modem was very basic, and I wanted to have a DNS server which would resolve to an internal IP address when the domain itself resolved to my public IP. Thus was born [RubyDNS]. This project [was originally built on](https://github.com/ioquatix/rubydns/tree/v0.8.5) top of [EventMachine], but a lack of support for [IPv6 at the time](https://github.com/ioquatix/rubydns/issues/45) and [other problems](https://github.com/ioquatix/rubydns/issues/14), meant that I started looking for other options. Around that time [Celluloid] was picking up steam. I had not encountered actors before and I wanted to learn more about it. So, [I reimplemented RubyDNS on top of Celluloid](https://github.com/ioquatix/rubydns/tree/v0.9.0) and this eventually became the first stable release.
|
@@ -109,11 +111,11 @@ def nested_sleepy(task: Async::Task.current)
|
|
109
111
|
end
|
110
112
|
|
111
113
|
Async do |task|
|
112
|
-
subtask = nested_sleepy
|
114
|
+
subtask = nested_sleepy(task: task)
|
113
115
|
end
|
114
116
|
```
|
115
117
|
|
116
|
-
This
|
118
|
+
This example creates a child `subtask` from the given parent `task`. It's the most efficient way to schedule a task. The task is executed until the first blocking operation, at which point it will yield control and `#async` will return. The result of this method is the task itself.
|
117
119
|
|
118
120
|
### Waiting for Results
|
119
121
|
|
data/Rakefile
CHANGED
data/async.gemspec
CHANGED
@@ -27,6 +27,8 @@ Gem::Specification.new do |spec|
|
|
27
27
|
|
28
28
|
spec.add_development_dependency "async-rspec", "~> 1.1"
|
29
29
|
|
30
|
+
spec.add_development_dependency "covered", "~> 0.10"
|
31
|
+
|
30
32
|
spec.add_development_dependency "bundler"
|
31
33
|
spec.add_development_dependency "rspec", "~> 3.6"
|
32
34
|
spec.add_development_dependency "rake"
|
data/lib/async/logger.rb
CHANGED
@@ -25,6 +25,22 @@ require 'logger'
|
|
25
25
|
|
26
26
|
module Async
|
27
27
|
class Logger
|
28
|
+
class Buffer < StringIO
|
29
|
+
def initialize(prefix = nil)
|
30
|
+
@prefix = prefix
|
31
|
+
|
32
|
+
super()
|
33
|
+
end
|
34
|
+
|
35
|
+
def puts(*args, prefix: @prefix)
|
36
|
+
args.each do |arg|
|
37
|
+
self.write(prefix) if prefix
|
38
|
+
|
39
|
+
super(arg)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
28
44
|
LEVELS = {debug: 0, info: 1, warn: 2, error: 3, fatal: 4}
|
29
45
|
|
30
46
|
LEVELS.each do |name, level|
|
@@ -89,21 +105,22 @@ module Async
|
|
89
105
|
end
|
90
106
|
|
91
107
|
def format(subject = nil, *arguments, &block)
|
92
|
-
buffer = StringIO.new
|
93
108
|
prefix = time_offset_prefix
|
94
109
|
indent = " " * prefix.size
|
95
110
|
|
111
|
+
buffer = Buffer.new("#{indent}| ")
|
112
|
+
|
96
113
|
if subject
|
97
114
|
format_subject(prefix, subject, output: buffer)
|
98
115
|
end
|
99
116
|
|
100
117
|
arguments.each do |argument|
|
101
|
-
format_argument(
|
118
|
+
format_argument(argument, output: buffer)
|
102
119
|
end
|
103
120
|
|
104
121
|
if block_given?
|
105
122
|
if block.arity.zero?
|
106
|
-
format_argument(
|
123
|
+
format_argument(yield, output: buffer)
|
107
124
|
else
|
108
125
|
yield(buffer, @terminal)
|
109
126
|
end
|
@@ -112,16 +129,16 @@ module Async
|
|
112
129
|
@output.write buffer.string
|
113
130
|
end
|
114
131
|
|
115
|
-
def format_argument(
|
132
|
+
def format_argument(argument, output: @output)
|
116
133
|
if argument.is_a? Exception
|
117
|
-
format_exception(
|
134
|
+
format_exception(argument, output: output)
|
118
135
|
else
|
119
|
-
format_value(
|
136
|
+
format_value(argument, output: output)
|
120
137
|
end
|
121
138
|
end
|
122
139
|
|
123
|
-
def format_exception(
|
124
|
-
output.puts "#{
|
140
|
+
def format_exception(exception, prefix = nil, pwd: Dir.pwd, output: @output)
|
141
|
+
output.puts " #{prefix}#{@exception_title_style}#{exception.class}#{@reset_style}: #{exception}"
|
125
142
|
|
126
143
|
exception.backtrace.each_with_index do |line, index|
|
127
144
|
path, offset, message = line.split(":")
|
@@ -129,25 +146,23 @@ module Async
|
|
129
146
|
# Make the path a bit more readable
|
130
147
|
path.gsub!(/^#{pwd}\//, "./")
|
131
148
|
|
132
|
-
output.puts "#{
|
149
|
+
output.puts " #{index == 0 ? "→" : " "} #{@exception_line_style}#{path}:#{offset}#{@reset_style} #{message}"
|
133
150
|
end
|
134
151
|
|
135
152
|
if exception.cause
|
136
|
-
|
137
|
-
|
138
|
-
format_exception(indent, exception.cause, "Caused by ", pwd: pwd, output: output)
|
153
|
+
format_exception(exception.cause, "Caused by ", pwd: pwd, output: output)
|
139
154
|
end
|
140
155
|
end
|
141
156
|
|
142
157
|
def format_subject(prefix, subject, output: @output)
|
143
|
-
output.puts "#{@
|
158
|
+
output.puts "#{@subject_style}#{subject}#{@reset_style}", prefix: "#{@prefix_style}#{prefix}: "
|
144
159
|
end
|
145
160
|
|
146
|
-
def format_value(
|
161
|
+
def format_value(value, output: @output)
|
147
162
|
string = value.to_s
|
148
163
|
|
149
164
|
string.each_line do |line|
|
150
|
-
output.puts "#{
|
165
|
+
output.puts "#{line}"
|
151
166
|
end
|
152
167
|
end
|
153
168
|
|
data/lib/async/version.rb
CHANGED
data/spec/async/reactor_spec.rb
CHANGED
data/spec/async/task_spec.rb
CHANGED
@@ -18,7 +18,8 @@
|
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
|
-
require '
|
21
|
+
require 'async/reactor'
|
22
|
+
require 'async/clock'
|
22
23
|
|
23
24
|
RSpec.describe Async::Task do
|
24
25
|
let(:reactor) {Async::Reactor.new}
|
@@ -188,7 +189,7 @@ RSpec.describe Async::Task do
|
|
188
189
|
state = :finished
|
189
190
|
end
|
190
191
|
|
191
|
-
time =
|
192
|
+
time = Async::Clock.measure do
|
192
193
|
reactor.run
|
193
194
|
end
|
194
195
|
|
data/spec/async/wrapper_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,26 +1,5 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'simplecov'
|
5
|
-
|
6
|
-
SimpleCov.start do
|
7
|
-
add_filter "/spec/"
|
8
|
-
end
|
9
|
-
|
10
|
-
if ENV['TRAVIS']
|
11
|
-
require 'coveralls'
|
12
|
-
Coveralls.wear!
|
13
|
-
end
|
14
|
-
rescue LoadError
|
15
|
-
warn "Could not load simplecov: #{$!}"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
require "bundler/setup"
|
20
|
-
require "async"
|
21
|
-
|
22
|
-
# Shared rspec helpers:
|
23
|
-
require "async/rspec"
|
2
|
+
require "covered/rspec"
|
24
3
|
|
25
4
|
RSpec.configure do |config|
|
26
5
|
# Enable flags like --only-failures and --next-failure
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.15.
|
4
|
+
version: 1.15.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01
|
11
|
+
date: 2019-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nio4r
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: covered
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.10'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: bundler
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -171,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
185
|
- !ruby/object:Gem::Version
|
172
186
|
version: '0'
|
173
187
|
requirements: []
|
174
|
-
rubygems_version: 3.0.
|
188
|
+
rubygems_version: 3.0.2
|
175
189
|
signing_key:
|
176
190
|
specification_version: 4
|
177
191
|
summary: Async is an asynchronous I/O framework based on nio4r.
|