async 0.15.0 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/async/version.rb +1 -1
- metadata +1 -4
- data/lib/async/container.rb +0 -70
- data/spec/async/container_spec.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b09ff3d20b66fd1a908bbf44ba04e10fb6b633cf
|
4
|
+
data.tar.gz: 287bc69ce12fb51c1b1412749ed3fe62473a6673
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3eee05641978320874385017b666d4e7daf02ebc2bfa22ce8eeab6ece962322a645b1e8d6896dc744ef1a428ba48f6f633ad27335dc7573c570ba97ee89bdbb
|
7
|
+
data.tar.gz: 50f17f1f2213b2afeeb5c0bfe63ed6aae31e98b81d45f9f6bacb1f752808278456ed9e7f19d928d9c7ab459f8ec3f78e638c5bf97a222dee078e6b3fddc0a196
|
data/lib/async/version.rb
CHANGED
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: 0.
|
4
|
+
version: 0.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -115,7 +115,6 @@ files:
|
|
115
115
|
- async.gemspec
|
116
116
|
- lib/async.rb
|
117
117
|
- lib/async/condition.rb
|
118
|
-
- lib/async/container.rb
|
119
118
|
- lib/async/logger.rb
|
120
119
|
- lib/async/node.rb
|
121
120
|
- lib/async/reactor.rb
|
@@ -123,7 +122,6 @@ files:
|
|
123
122
|
- lib/async/version.rb
|
124
123
|
- lib/async/wrapper.rb
|
125
124
|
- spec/async/condition_spec.rb
|
126
|
-
- spec/async/container_spec.rb
|
127
125
|
- spec/async/node_spec.rb
|
128
126
|
- spec/async/reactor/nested_spec.rb
|
129
127
|
- spec/async/reactor_spec.rb
|
@@ -156,7 +154,6 @@ specification_version: 4
|
|
156
154
|
summary: Async is an asynchronous I/O framework based on nio4r.
|
157
155
|
test_files:
|
158
156
|
- spec/async/condition_spec.rb
|
159
|
-
- spec/async/container_spec.rb
|
160
157
|
- spec/async/node_spec.rb
|
161
158
|
- spec/async/reactor/nested_spec.rb
|
162
159
|
- spec/async/reactor_spec.rb
|
data/lib/async/container.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
require_relative 'reactor'
|
22
|
-
require 'thread'
|
23
|
-
|
24
|
-
module Async
|
25
|
-
# TODO Move this into it's own gem, since it's really not required for async to work - it's only really for servers and this implementation is very basic.
|
26
|
-
# Manages a reactor within one or more threads.
|
27
|
-
module Container
|
28
|
-
def self.new(klass: ThreadContainer, **options, &block)
|
29
|
-
klass.new(**options, &block)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
class ThreadContainer
|
34
|
-
def initialize(concurrency: 1, &block)
|
35
|
-
@reactors = concurrency.times.collect do
|
36
|
-
Async::Reactor.new
|
37
|
-
end
|
38
|
-
|
39
|
-
@threads = @reactors.collect do |reactor|
|
40
|
-
Thread.new do
|
41
|
-
Thread.current.abort_on_exception = true
|
42
|
-
|
43
|
-
reactor.run(&block)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def stop
|
49
|
-
@reactors.each(&:stop)
|
50
|
-
@threads.each(&:join)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
class ProcessContainer
|
55
|
-
def initialize(concurrency: 1, &block)
|
56
|
-
@pids = concurrency.times.collect do
|
57
|
-
fork do
|
58
|
-
Async::Reactor.run(&block)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def stop
|
64
|
-
@pids.each do |pid|
|
65
|
-
Process.kill(:INT, pid) rescue nil
|
66
|
-
Process.wait(pid)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
require "async/container"
|
22
|
-
|
23
|
-
RSpec.describe Async::Container do
|
24
|
-
it "can run concurrently" do
|
25
|
-
count = 0
|
26
|
-
|
27
|
-
container = described_class.new do
|
28
|
-
count += 1
|
29
|
-
end
|
30
|
-
|
31
|
-
container.stop
|
32
|
-
|
33
|
-
expect(count).to be == 1
|
34
|
-
end
|
35
|
-
end
|