delayer-deferred 1.1.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +77 -3
- data/delayer-deferred.gemspec +1 -0
- data/lib/delayer/deferred.rb +11 -10
- data/lib/delayer/deferred/chain.rb +10 -0
- data/lib/delayer/deferred/chain/await.rb +43 -0
- data/lib/delayer/deferred/chain/base.rb +35 -0
- data/lib/delayer/deferred/chain/next.rb +16 -0
- data/lib/delayer/deferred/chain/trap.rb +16 -0
- data/lib/delayer/deferred/deferred.rb +4 -72
- data/lib/delayer/deferred/deferredable.rb +8 -158
- data/lib/delayer/deferred/deferredable/awaitable.rb +27 -0
- data/lib/delayer/deferred/deferredable/chainable.rb +155 -0
- data/lib/delayer/deferred/deferredable/graph.rb +118 -0
- data/lib/delayer/deferred/deferredable/node_sequence.rb +158 -0
- data/lib/delayer/deferred/deferredable/trigger.rb +34 -0
- data/lib/delayer/deferred/enumerator.rb +5 -7
- data/lib/delayer/deferred/error.rb +9 -0
- data/lib/delayer/deferred/promise.rb +78 -0
- data/lib/delayer/deferred/request.rb +61 -0
- data/lib/delayer/deferred/response.rb +26 -0
- data/lib/delayer/deferred/thread.rb +29 -14
- data/lib/delayer/deferred/tools.rb +20 -10
- data/lib/delayer/deferred/version.rb +1 -1
- data/lib/delayer/deferred/worker.rb +112 -0
- data/test/deferred_test.rb +14 -0
- data/test/enumerable_test.rb +1 -1
- data/test/graph_test.rb +52 -0
- data/test/helper.rb +8 -3
- data/test/promise_test.rb +91 -0
- data/test/thread_test.rb +9 -5
- metadata +35 -3
data/test/deferred_test.rb
CHANGED
@@ -98,6 +98,20 @@ describe(Delayer::Deferred) do
|
|
98
98
|
assert succeed, "Deferred did not executed."
|
99
99
|
end
|
100
100
|
|
101
|
+
it "assign twice" do
|
102
|
+
succeed = false
|
103
|
+
delayer = Delayer.generate_class
|
104
|
+
assert_raises(Delayer::Deferred::MultipleAssignmentError) do
|
105
|
+
eval_all_events(delayer) do
|
106
|
+
defer = delayer.Deferred.new.next {
|
107
|
+
succeed = 0
|
108
|
+
}
|
109
|
+
defer.next{ succeed = 1 }
|
110
|
+
defer.next{ succeed = 2 }
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
101
115
|
describe "Deferred.when" do
|
102
116
|
it "give 3 deferred" do
|
103
117
|
result = failure = false
|
data/test/enumerable_test.rb
CHANGED
data/test/graph_test.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require_relative 'helper'
|
3
|
+
|
4
|
+
describe(Delayer::Deferred) do
|
5
|
+
include TestUtils
|
6
|
+
|
7
|
+
before do
|
8
|
+
Delayer.default = Delayer.generate_class
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'auto execution Promise' do
|
12
|
+
it 'should include Promise result of Promise.graph' do
|
13
|
+
promise = Delayer::Deferred::Promise.new
|
14
|
+
assert_includes promise.graph, 'egg', ->{"[[#{promise.graph_draw}]]"}
|
15
|
+
assert_includes promise.graph, 'reserved', ->{"[[#{promise.graph_draw}]]"}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'Promise' do
|
20
|
+
it 'should include Promise result of Promise.graph' do
|
21
|
+
promise = Delayer::Deferred::Promise.new(true)
|
22
|
+
assert_includes promise.graph, 'egg', ->{"[[#{promise.graph_draw}]]"}
|
23
|
+
assert_includes promise.graph, 'fresh', ->{"[[#{promise.graph_draw}]]"}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'Chain' do
|
28
|
+
it 'should include ' do
|
29
|
+
promise = Delayer::Deferred::Promise.new.next{ ; }
|
30
|
+
assert_includes promise.graph, 'graph_test.rb', ->{"[[#{promise.graph_draw}]]"}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'Awaiting' do
|
35
|
+
it 'await' do
|
36
|
+
promise_a = Delayer::Deferred::Promise.new(true).next{ |buf|
|
37
|
+
buf << :a
|
38
|
+
}.next{ |buf|
|
39
|
+
buf << :b
|
40
|
+
}.trap{ |buf|
|
41
|
+
buf << :c
|
42
|
+
}
|
43
|
+
promise_b = Delayer::Deferred::Promise.new.next{
|
44
|
+
+promise_a << :e
|
45
|
+
}.trap{ |buf|
|
46
|
+
buf << :f
|
47
|
+
}
|
48
|
+
eval_all_events
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
data/test/helper.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
require 'bundler/setup'
|
2
|
-
require 'minitest/autorun'
|
3
2
|
|
4
|
-
require 'delayer/deferred'
|
5
3
|
require 'securerandom'
|
6
4
|
require 'set'
|
7
5
|
require 'timeout'
|
8
|
-
|
9
6
|
require_relative 'testutils'
|
7
|
+
|
8
|
+
require 'simplecov'
|
9
|
+
SimpleCov.start do
|
10
|
+
add_filter "/test/"
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'delayer/deferred'
|
14
|
+
require 'minitest/autorun'
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require_relative 'helper'
|
4
|
+
|
5
|
+
describe(Delayer::Deferred::Promise) do
|
6
|
+
include TestUtils
|
7
|
+
|
8
|
+
before do
|
9
|
+
Delayer.default = Delayer.generate_class
|
10
|
+
@delayer = Delayer.generate_class
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'get instance' do
|
14
|
+
it 'default delayer' do
|
15
|
+
assert_instance_of Delayer::Deferred::Promise, Delayer::Deferred::Promise.new
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'another delayer' do
|
19
|
+
promise = @delayer.Promise.new
|
20
|
+
assert_instance_of @delayer.Promise, promise
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "with block" do
|
24
|
+
before do
|
25
|
+
@promise = @delayer.Promise.new{ ; }
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'was generated' do
|
29
|
+
assert_kind_of Delayer::Deferred::Chain::Next, @promise
|
30
|
+
end
|
31
|
+
|
32
|
+
it "doesn't have child" do
|
33
|
+
refute @promise.has_child?
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'chain' do
|
39
|
+
before do
|
40
|
+
@promise = @delayer.Promise.new(true)
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'next' do
|
44
|
+
before do
|
45
|
+
@record = nil
|
46
|
+
@chain = @promise.next{|x| @record = x + 1 }
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should execute next block if called promise#call' do
|
50
|
+
val = rand(1000)
|
51
|
+
eval_all_events(@delayer) do
|
52
|
+
@promise.call(val)
|
53
|
+
end
|
54
|
+
assert_equal val + 1, @record, ->{ "next block did not executed.\n[[#{@chain.graph_draw}]]" }
|
55
|
+
end
|
56
|
+
|
57
|
+
it "shouldn't execute next block if called promise#fail" do
|
58
|
+
val = rand(1000)
|
59
|
+
eval_all_events(@delayer) do
|
60
|
+
@promise.fail(val)
|
61
|
+
end
|
62
|
+
refute_equal val + 1, @record, ->{ "next block did executed.\n[[#{@chain.graph_draw}]]" }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'trap' do
|
67
|
+
before do
|
68
|
+
@record = nil
|
69
|
+
@chain = @promise.trap{|x| @record = x + 1 }
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should execute trap block if called promise#fail' do
|
73
|
+
val = rand(1000)
|
74
|
+
eval_all_events(@delayer) do
|
75
|
+
@promise.fail(val)
|
76
|
+
end
|
77
|
+
assert_equal val + 1, @record, ->{ "trap block did not executed.\n[[#{@chain.graph_draw}]]" }
|
78
|
+
end
|
79
|
+
|
80
|
+
it "shouldn't execute trap block if called promise#call" do
|
81
|
+
val = rand(1000)
|
82
|
+
eval_all_events(@delayer) do
|
83
|
+
@promise.call(val)
|
84
|
+
end
|
85
|
+
refute_equal val + 1, @record, ->{ "trap block did executed.\n[[#{@chain.graph_draw}]]" }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
data/test/thread_test.rb
CHANGED
@@ -46,6 +46,7 @@ describe(Thread) do
|
|
46
46
|
thread = succeed = failure = result = false
|
47
47
|
uuid = SecureRandom.uuid
|
48
48
|
delayer = Delayer.generate_class
|
49
|
+
assert_equal delayer, delayer.Deferred.Thread.delayer
|
49
50
|
eval_all_events(delayer) do
|
50
51
|
delayer.Deferred.Thread.new {
|
51
52
|
thread = true
|
@@ -55,7 +56,7 @@ describe(Thread) do
|
|
55
56
|
result = param
|
56
57
|
}.trap{ |exception|
|
57
58
|
failure = exception } end
|
58
|
-
assert_equal false, failure
|
59
|
+
assert_equal false, failure, 'Unexpected failed.'
|
59
60
|
assert thread, "Thread did not executed."
|
60
61
|
assert succeed, "next block did not executed."
|
61
62
|
assert_equal uuid, result
|
@@ -101,16 +102,19 @@ describe(Thread) do
|
|
101
102
|
result = failure = false
|
102
103
|
delayer = Delayer.generate_class
|
103
104
|
uuid = SecureRandom.uuid
|
104
|
-
eval_all_events(delayer) do
|
105
|
+
node = eval_all_events(delayer) do
|
105
106
|
delayer.Deferred.new.next{
|
106
|
-
delayer.Deferred.
|
107
|
-
|
107
|
+
delayer.Deferred.new.next{
|
108
|
+
delayer.Deferred.Thread.new{
|
109
|
+
uuid
|
110
|
+
}
|
111
|
+
}
|
108
112
|
}.next{ |value|
|
109
113
|
result = value
|
110
114
|
}.trap{ |exception|
|
111
115
|
failure = exception }
|
112
116
|
end
|
113
|
-
assert_equal uuid, result
|
117
|
+
assert_equal uuid, result, ->{ "[[#{node.graph_draw}]]" }
|
114
118
|
assert_equal false, failure
|
115
119
|
end
|
116
120
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delayer-deferred
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Toshiaki Asai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: delayer
|
@@ -72,6 +72,20 @@ dependencies:
|
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '5.7'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: simplecov
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
75
89
|
- !ruby/object:Gem::Dependency
|
76
90
|
name: ruby-prof
|
77
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,20 +156,36 @@ files:
|
|
142
156
|
- Rakefile
|
143
157
|
- delayer-deferred.gemspec
|
144
158
|
- lib/delayer/deferred.rb
|
159
|
+
- lib/delayer/deferred/chain.rb
|
160
|
+
- lib/delayer/deferred/chain/await.rb
|
161
|
+
- lib/delayer/deferred/chain/base.rb
|
162
|
+
- lib/delayer/deferred/chain/next.rb
|
163
|
+
- lib/delayer/deferred/chain/trap.rb
|
145
164
|
- lib/delayer/deferred/deferred.rb
|
146
165
|
- lib/delayer/deferred/deferredable.rb
|
166
|
+
- lib/delayer/deferred/deferredable/awaitable.rb
|
167
|
+
- lib/delayer/deferred/deferredable/chainable.rb
|
168
|
+
- lib/delayer/deferred/deferredable/graph.rb
|
169
|
+
- lib/delayer/deferred/deferredable/node_sequence.rb
|
170
|
+
- lib/delayer/deferred/deferredable/trigger.rb
|
147
171
|
- lib/delayer/deferred/enumerable.rb
|
148
172
|
- lib/delayer/deferred/enumerator.rb
|
149
173
|
- lib/delayer/deferred/error.rb
|
174
|
+
- lib/delayer/deferred/promise.rb
|
175
|
+
- lib/delayer/deferred/request.rb
|
176
|
+
- lib/delayer/deferred/response.rb
|
150
177
|
- lib/delayer/deferred/result_container.rb
|
151
178
|
- lib/delayer/deferred/thread.rb
|
152
179
|
- lib/delayer/deferred/tools.rb
|
153
180
|
- lib/delayer/deferred/version.rb
|
181
|
+
- lib/delayer/deferred/worker.rb
|
154
182
|
- test/deferred_benchmark.rb
|
155
183
|
- test/deferred_profiler.rb
|
156
184
|
- test/deferred_test.rb
|
157
185
|
- test/enumerable_test.rb
|
186
|
+
- test/graph_test.rb
|
158
187
|
- test/helper.rb
|
188
|
+
- test/promise_test.rb
|
159
189
|
- test/testutils.rb
|
160
190
|
- test/thread_test.rb
|
161
191
|
homepage: https://github.com/toshia/delayer-deferred
|
@@ -178,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
178
208
|
version: '0'
|
179
209
|
requirements: []
|
180
210
|
rubyforge_project:
|
181
|
-
rubygems_version: 2.6.
|
211
|
+
rubygems_version: 2.6.11
|
182
212
|
signing_key:
|
183
213
|
specification_version: 4
|
184
214
|
summary: Deferred for Delayer
|
@@ -187,6 +217,8 @@ test_files:
|
|
187
217
|
- test/deferred_profiler.rb
|
188
218
|
- test/deferred_test.rb
|
189
219
|
- test/enumerable_test.rb
|
220
|
+
- test/graph_test.rb
|
190
221
|
- test/helper.rb
|
222
|
+
- test/promise_test.rb
|
191
223
|
- test/testutils.rb
|
192
224
|
- test/thread_test.rb
|