async 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 881ace206b49720782f4bf53c50cea4997efe5ac
4
- data.tar.gz: f9b1ecbd174370ce7b62c6f4fdbd6a0dddda858c
3
+ metadata.gz: 58e790ceb3a44709f35f90e0cb35c15a9a251ada
4
+ data.tar.gz: 052dfc0e8afd64422e0a1703134b333c9271b8f6
5
5
  SHA512:
6
- metadata.gz: ef14bfef3d114ef2ee95f15fc239efad2b1f91efe5b0e99d8243dc3d5d487188cf41a7c5e36708c07d8f007db0b5fd7dfaf3ba731ab2a3fb98751bf0a6938b8c
7
- data.tar.gz: fc1eeaadb11ec7dafe4e21ea2afa251508d1eaab8820d86b4e8a93aa7eca1828caa3c9bf42384cae7aec11afca8a0159b608fd732e26dcdf25118832fbcaa748
6
+ metadata.gz: 02e888c50e3dd0e20798fc53b2b5f83f7c4d66e6b4686cac13e0efd5704fffc13836933df20d72e8731a4db168a7c0f42266e18dee4bc76f54b52f3d47173ed1
7
+ data.tar.gz: 59050ea66f4f9a780b1e78c1d646cb8a178f43535d10ed5d75d38b9020da3c3984779c6016a7b962a35b24443e11081d64da891606a8251a1be6acb43138f746
data/async.gemspec CHANGED
@@ -26,9 +26,9 @@ Gem::Specification.new do |spec|
26
26
  spec.add_runtime_dependency "nio4r"
27
27
  spec.add_runtime_dependency "timers", "~> 4.1"
28
28
 
29
- spec.add_development_dependency "async-rspec", "~> 1.0"
29
+ spec.add_development_dependency "async-rspec", "~> 1.1"
30
30
 
31
31
  spec.add_development_dependency "bundler", "~> 1.3"
32
- spec.add_development_dependency "rspec", "~> 3.4"
32
+ spec.add_development_dependency "rspec", "~> 3.6"
33
33
  spec.add_development_dependency "rake"
34
34
  end
@@ -0,0 +1,70 @@
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
data/lib/async/node.rb CHANGED
@@ -92,7 +92,7 @@ module Async
92
92
 
93
93
  # Whether the node can be consumed safely. By default, checks if the
94
94
  # children set is empty.
95
- # @return [Boolean]
95
+ # @return [Boolean]
96
96
  def finished?
97
97
  @children.empty?
98
98
  end
@@ -108,7 +108,7 @@ module Async
108
108
  end
109
109
 
110
110
  # Remove a given child node.
111
- # @param child [Node]
111
+ # @param child [Node]
112
112
  def reap(child)
113
113
  @children.delete(child)
114
114
  end
data/lib/async/reactor.rb CHANGED
@@ -106,7 +106,7 @@ module Async
106
106
  @selector.register(*args)
107
107
  end
108
108
 
109
- # Stop the reactor at the earliest convenience.
109
+ # Stop the reactor at the earliest convenience. Can be called from a different thread safely.
110
110
  # @return [void]
111
111
  def stop
112
112
  unless @stopped
data/lib/async/version.rb CHANGED
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Async
22
- VERSION = "0.14.0"
22
+ VERSION = "0.15.0"
23
23
  end
@@ -0,0 +1,35 @@
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
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.14.0
4
+ version: 0.15.0
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-05-24 00:00:00.000000000 Z
11
+ date: 2017-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nio4r
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.0'
47
+ version: '1.1'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.0'
54
+ version: '1.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '3.4'
75
+ version: '3.6'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '3.4'
82
+ version: '3.6'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -115,6 +115,7 @@ files:
115
115
  - async.gemspec
116
116
  - lib/async.rb
117
117
  - lib/async/condition.rb
118
+ - lib/async/container.rb
118
119
  - lib/async/logger.rb
119
120
  - lib/async/node.rb
120
121
  - lib/async/reactor.rb
@@ -122,6 +123,7 @@ files:
122
123
  - lib/async/version.rb
123
124
  - lib/async/wrapper.rb
124
125
  - spec/async/condition_spec.rb
126
+ - spec/async/container_spec.rb
125
127
  - spec/async/node_spec.rb
126
128
  - spec/async/reactor/nested_spec.rb
127
129
  - spec/async/reactor_spec.rb
@@ -154,6 +156,7 @@ specification_version: 4
154
156
  summary: Async is an asynchronous I/O framework based on nio4r.
155
157
  test_files:
156
158
  - spec/async/condition_spec.rb
159
+ - spec/async/container_spec.rb
157
160
  - spec/async/node_spec.rb
158
161
  - spec/async/reactor/nested_spec.rb
159
162
  - spec/async/reactor_spec.rb