async 0.11.0 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/README.md +30 -30
- data/async.gemspec +1 -1
- data/lib/async/reactor.rb +8 -8
- data/lib/async/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 258d52bc85cb637bab0e3654089c848850ec8cd2
|
4
|
+
data.tar.gz: 8981a28373b74a1e0eb70049a722ca54e47a7c0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed62d3ec9840675cf7ab5c7f9f248ecbd55eebf0161631681a5ced37696bb48f97c3a4ba0bde7eb75adf0058da594345398f7774bdbbf22f540799132bb5b2e2
|
7
|
+
data.tar.gz: 9b60cf5994d40adc383fd346681cdc6f2e1bf7d40a0ad43bc9370755fd851492fec18e61cafa1abf6fe71392d767a1608a787e5aade7d171bb173839d27d723b
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -48,41 +48,41 @@ require 'async'
|
|
48
48
|
require 'async/tcp_socket'
|
49
49
|
|
50
50
|
def echo_server
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
51
|
+
Async::Reactor.run do |task|
|
52
|
+
# This is a synchronous block within the current task:
|
53
|
+
task.with(TCPServer.new('localhost', 9000)) do |server|
|
54
|
+
|
55
|
+
# This is an asynchronous block within the current reactor:
|
56
|
+
task.reactor.with(server.accept) do |client|
|
57
|
+
data = client.read(512)
|
58
|
+
|
59
|
+
task.sleep(rand)
|
60
|
+
|
61
|
+
client.write(data)
|
62
|
+
end while true
|
63
|
+
end
|
64
|
+
end
|
65
65
|
end
|
66
66
|
|
67
67
|
def echo_client(data)
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
68
|
+
Async::Reactor.run do |task|
|
69
|
+
Async::TCPServer.connect('localhost', 9000) do |socket|
|
70
|
+
socket.write(data)
|
71
|
+
puts "echo_client: #{socket.read(512)}"
|
72
|
+
end
|
73
|
+
end
|
74
74
|
end
|
75
75
|
|
76
76
|
Async::Reactor.run do
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
77
|
+
# Start the echo server:
|
78
|
+
server = echo_server
|
79
|
+
|
80
|
+
5.times.collect do |i|
|
81
|
+
echo_client("Hello World #{i}")
|
82
|
+
end.each(&:wait) # Wait until all clients are finished.
|
83
|
+
|
84
|
+
# Terminate the server and all tasks created within it's async scope:
|
85
|
+
server.stop
|
86
86
|
end
|
87
87
|
```
|
88
88
|
|
@@ -122,7 +122,7 @@ dropped.
|
|
122
122
|
## See Also
|
123
123
|
|
124
124
|
- [async-dns](https://github.com/socketry/async-dns) — Asynchronous DNS resolver and server.
|
125
|
-
- [rubydns](https://github.com/
|
125
|
+
- [rubydns](https://github.com/ioquatix/rubydns) — A easy to use Ruby DNS server.
|
126
126
|
|
127
127
|
## License
|
128
128
|
|
data/async.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
spec.has_rdoc = "yard"
|
23
23
|
|
24
|
-
spec.required_ruby_version = ">= 2.
|
24
|
+
spec.required_ruby_version = ">= 2.0.0"
|
25
25
|
|
26
26
|
spec.add_runtime_dependency "nio4r"
|
27
27
|
spec.add_runtime_dependency "timers", "~> 4.1"
|
data/lib/async/reactor.rb
CHANGED
@@ -116,20 +116,20 @@ module Async
|
|
116
116
|
# - +ve: timers waiting to fire
|
117
117
|
interval = 0 if interval && interval < 0
|
118
118
|
|
119
|
-
Async.logger.debug
|
120
|
-
Async.logger.debug
|
119
|
+
Async.logger.debug{"[#{self} Pre] Updating #{@children.count} children..."}
|
120
|
+
Async.logger.debug{@children.collect{|child| [child.to_s, child.alive?]}.inspect}
|
121
121
|
# As timeouts may have been updated, and caused fibers to complete, we should check this.
|
122
122
|
|
123
123
|
# If there is nothing to do, then finish:
|
124
|
-
Async.logger.debug
|
124
|
+
Async.logger.debug{"[#{self}] @children.empty? = #{@children.empty?} && interval #{interval.inspect}"}
|
125
125
|
return if @children.empty? && interval.nil?
|
126
126
|
|
127
|
-
Async.logger.debug
|
127
|
+
Async.logger.debug{"Selecting with #{@children.count} fibers interval = #{interval}..."}
|
128
128
|
if monitors = @selector.select(interval)
|
129
129
|
monitors.each do |monitor|
|
130
|
-
if
|
130
|
+
if fiber = monitor.value
|
131
131
|
# Async.logger.debug "Resuming task #{task} due to IO..."
|
132
|
-
|
132
|
+
fiber.resume
|
133
133
|
end
|
134
134
|
end
|
135
135
|
end
|
@@ -137,8 +137,8 @@ module Async
|
|
137
137
|
|
138
138
|
return self
|
139
139
|
ensure
|
140
|
-
Async.logger.debug
|
141
|
-
Async.logger.debug
|
140
|
+
Async.logger.debug{"[#{self} Ensure] Exiting run-loop (stopped: #{@stopped} exception: #{$!})..."}
|
141
|
+
Async.logger.debug{@children.collect{|child| [child.to_s, child.alive?]}.inspect}
|
142
142
|
@stopped = true
|
143
143
|
end
|
144
144
|
|
data/lib/async/version.rb
CHANGED
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: 0.11.
|
4
|
+
version: 0.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nio4r
|
@@ -147,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
147
147
|
requirements:
|
148
148
|
- - ">="
|
149
149
|
- !ruby/object:Gem::Version
|
150
|
-
version: 2.
|
150
|
+
version: 2.0.0
|
151
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
152
|
requirements:
|
153
153
|
- - ">="
|