async 1.4.1 → 1.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44eb7af07e00729f3e1ecc10e98cd7cda6d09a117a9d3f62e33a22d5fc7068b4
4
- data.tar.gz: 115e88de10b11bb887b3a17c1c82f29d9ea1d082e13ac874e5311c37cfc7cdaf
3
+ metadata.gz: fbcd86e787f3949c50b5cc5f2aa05dd538bfc51bd6b56ee13f9a401e8becf567
4
+ data.tar.gz: e6e35d12fa6c08dd70e31de4ad8689506f80a6daa90a35af98cda331bf06e139
5
5
  SHA512:
6
- metadata.gz: 7a48d12ecd04670b4d552772bf882c190230aa15cb1946f0558d46f3bf9b50d321d160128d2667db57b6531af26ca01a68457754c40b9aa91135bfb63d36e983
7
- data.tar.gz: b56e6e3e0ccf58fd47f70f99209badf9c536430ffe3d8fac7f4f6694670c06d2e4861e61f87d4767822a01264b1b0ad5fede8ab23e8d35a9a4d5cdc8ba6cc537
6
+ metadata.gz: 668b4300208b250bd012ee41d3aa4612f22e3d7b6b22904396be2b52ea7eaef8ef5273b5996eaeebbfcfb3d072def93137614d58f1ef5a112ef75f17067c598b
7
+ data.tar.gz: 48dc3517c920260e26f3e1f2bd0835d857d32c5c253e634562a70f6f145a12d338e3e4f48adff206c0d23b0f4dde096522908970a49c29d07682aa95d2df3ec4
@@ -7,7 +7,10 @@ addons:
7
7
  packages:
8
8
  - bind9
9
9
 
10
- before_script: sudo sh -c 'echo 0 > /proc/sys/net/ipv6/conf/all/disable_ipv6'
10
+ before_script:
11
+ - sudo sh -c 'echo 0 > /proc/sys/net/ipv6/conf/all/disable_ipv6'
12
+ - gem update --system
13
+ - gem install bundler
11
14
 
12
15
  matrix:
13
16
  include:
@@ -57,29 +57,5 @@ module Async
57
57
 
58
58
  return nil
59
59
  end
60
-
61
- # Signal to a given task that it should resume operations.
62
- # @return [void]
63
- def resume(value = nil, task: Task.current)
64
- return if @waiting.empty?
65
-
66
- task.reactor << Signal.new(@waiting, value)
67
-
68
- @waiting = []
69
-
70
- return nil
71
- end
72
-
73
- Signal = Struct.new(:waiting, :value) do
74
- def alive?
75
- true
76
- end
77
-
78
- def resume
79
- waiting.each do |fiber|
80
- fiber.resume(value) if fiber.alive?
81
- end
82
- end
83
- end
84
60
  end
85
61
  end
@@ -0,0 +1,46 @@
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 'notification'
22
+
23
+ module Async
24
+ # A queue which allows items to be processed in order.
25
+ class Queue < Notification
26
+ def initialize
27
+ super
28
+
29
+ @items = []
30
+ end
31
+
32
+ def enqueue item
33
+ @items.push(item)
34
+
35
+ self.signal unless self.empty?
36
+ end
37
+
38
+ def dequeue
39
+ while @items.empty?
40
+ self.wait
41
+ end
42
+
43
+ @items.shift
44
+ end
45
+ end
46
+ end
@@ -65,7 +65,7 @@ module Async
65
65
  @status = :initialized
66
66
  @result = nil
67
67
 
68
- @condition = nil
68
+ @finished = nil
69
69
 
70
70
  @fiber = Fiber.new do |*args|
71
71
  set!
@@ -99,7 +99,7 @@ module Async
99
99
 
100
100
  # Yield back to the reactor and allow other fibers to execute.
101
101
  def yield
102
- self.sleep(0)
102
+ reactor.yield
103
103
  end
104
104
 
105
105
  # @attr fiber [Fiber] The fiber which is being used for the execution of this task.
@@ -134,8 +134,8 @@ module Async
134
134
  raise RuntimeError.new("Cannot wait on own fiber") if Fiber.current.equal?(@fiber)
135
135
 
136
136
  if running?
137
- @condition ||= Condition.new
138
- @condition.wait
137
+ @finished ||= Condition.new
138
+ @finished.wait
139
139
  else
140
140
  Task.yield {@result}
141
141
  end
@@ -186,8 +186,8 @@ module Async
186
186
  consume
187
187
 
188
188
  # If this task was being used as a future, signal completion here:
189
- if @condition
190
- @condition.signal(@result)
189
+ if @finished
190
+ @finished.signal(@result)
191
191
  end
192
192
  end
193
193
 
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Async
22
- VERSION = "1.4.1"
22
+ VERSION = "1.5.0"
23
23
  end
@@ -0,0 +1,47 @@
1
+ # Copyright, 2018, 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
+ RSpec.describe Async.logger do
22
+ let!(:debug) {$DEBUG}
23
+ after {$DEBUG = debug}
24
+
25
+ let!(:verbose) {$VERBOSE}
26
+ after {$VERBOSE = verbose}
27
+
28
+ it 'should set default log level' do
29
+ $DEBUG = false
30
+ $VERBOSE = false
31
+
32
+ expect(Async.default_log_level).to be == Logger::WARN
33
+ end
34
+
35
+ it 'should set default log level based on $DEBUG' do
36
+ $DEBUG = true
37
+
38
+ expect(Async.default_log_level).to be == Logger::DEBUG
39
+ end
40
+
41
+ it 'should set default log level based on $VERBOSE' do
42
+ $DEBUG = false
43
+ $VERBOSE = true
44
+
45
+ expect(Async.default_log_level).to be == Logger::INFO
46
+ end
47
+ end
@@ -0,0 +1,40 @@
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/queue'
22
+
23
+ require_relative 'condition_examples'
24
+
25
+ RSpec.describe Async::Queue do
26
+ include_context Async::RSpec::Reactor
27
+
28
+ it 'should process items in order' do
29
+ reactor.async do |task|
30
+ 10.times do |i|
31
+ task.sleep(0.001)
32
+ subject.enqueue(i)
33
+ end
34
+ end
35
+
36
+ 10.times do |j|
37
+ expect(subject.dequeue).to be == j
38
+ end
39
+ end
40
+ end
@@ -96,6 +96,34 @@ RSpec.describe Async::Reactor do
96
96
  end
97
97
  end
98
98
 
99
+ describe '#timeout' do
100
+ let(:duration) {1}
101
+
102
+ it "stops immediately" do
103
+ start_time = Time.now
104
+
105
+ described_class.run do |task|
106
+ condition = Async::Condition.new
107
+
108
+ task.timeout(duration) do
109
+ task.async do
110
+ condition.wait
111
+ end
112
+
113
+ condition.signal
114
+
115
+ task.yield
116
+
117
+ task.children.each(&:wait)
118
+ end
119
+ end
120
+
121
+ duration = Time.now - start_time
122
+
123
+ expect(duration).to be < 0.1
124
+ end
125
+ end
126
+
99
127
  describe '#to_s' do
100
128
  it "shows stopped=" do
101
129
  expect(subject.to_s).to include "stopped"
@@ -47,4 +47,17 @@ RSpec.describe Async::Wrapper do
47
47
  output.close
48
48
  end
49
49
  end
50
+
51
+ describe '#reactor=' do
52
+ include_context Async::RSpec::Reactor
53
+
54
+ it 'can assign a wrapper to a reactor' do
55
+ input.reactor = reactor
56
+
57
+ expect(input.reactor).to be == reactor
58
+
59
+ input.close
60
+ output.close
61
+ end
62
+ end
50
63
  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: 1.4.1
4
+ version: 1.5.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: 2018-03-27 00:00:00.000000000 Z
11
+ date: 2018-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nio4r
@@ -123,6 +123,7 @@ files:
123
123
  - lib/async/measure.rb
124
124
  - lib/async/node.rb
125
125
  - lib/async/notification.rb
126
+ - lib/async/queue.rb
126
127
  - lib/async/reactor.rb
127
128
  - lib/async/task.rb
128
129
  - lib/async/version.rb
@@ -133,9 +134,11 @@ files:
133
134
  - papers/1987 ODell.pdf
134
135
  - spec/async/condition_examples.rb
135
136
  - spec/async/condition_spec.rb
137
+ - spec/async/logger_spec.rb
136
138
  - spec/async/node_spec.rb
137
139
  - spec/async/notification_spec.rb
138
140
  - spec/async/performance_spec.rb
141
+ - spec/async/queue_spec.rb
139
142
  - spec/async/reactor/nested_spec.rb
140
143
  - spec/async/reactor_spec.rb
141
144
  - spec/async/task_spec.rb
@@ -168,9 +171,11 @@ summary: Async is an asynchronous I/O framework based on nio4r.
168
171
  test_files:
169
172
  - spec/async/condition_examples.rb
170
173
  - spec/async/condition_spec.rb
174
+ - spec/async/logger_spec.rb
171
175
  - spec/async/node_spec.rb
172
176
  - spec/async/notification_spec.rb
173
177
  - spec/async/performance_spec.rb
178
+ - spec/async/queue_spec.rb
174
179
  - spec/async/reactor/nested_spec.rb
175
180
  - spec/async/reactor_spec.rb
176
181
  - spec/async/task_spec.rb