delayer-deferred 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/delayer-deferred.gemspec +3 -0
- data/lib/delayer/deferred/deferred.rb +14 -5
- data/lib/delayer/deferred/tools.rb +2 -2
- data/lib/delayer/deferred/version.rb +1 -1
- data/test/deferred_test.rb +41 -0
- metadata +44 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37e4d01b997cbcc9e878f5743755883123843d4f
|
4
|
+
data.tar.gz: f43c013e223a6f30da88a500237fbb1920473e26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e53e3785d68e9c69431742d81efaa936ee80a93cf726c0c42f022732e120cbb7b5a08036743081b780e9548d7fbe4d797b1688c2a4ec68fd8a4e0a072770a860
|
7
|
+
data.tar.gz: dd6d334922b6e999fd2f2eb90fc3fccd656d038d76cfa10b6742961246c1feaca452862837a57c8a3dc33d2ed4257df38fbc401f15e5a40f505f8b8fdab53c6f
|
data/.gitignore
CHANGED
data/delayer-deferred.gemspec
CHANGED
@@ -26,4 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
27
27
|
spec.add_development_dependency "minitest", "~> 5.7"
|
28
28
|
spec.add_development_dependency "ruby-prof"
|
29
|
+
spec.add_development_dependency 'guard'
|
30
|
+
spec.add_development_dependency 'guard-shell'
|
31
|
+
spec.add_development_dependency 'guard-rake'
|
29
32
|
end
|
@@ -51,12 +51,13 @@ module Delayer::Deferred
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def self.fiber(&block)
|
54
|
-
@_fiber ||=
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
@_fiber ||= _gen_new_fiber
|
55
|
+
begin
|
56
|
+
result = @_fiber.resume(block)
|
57
|
+
rescue FiberError
|
58
|
+
@_fiber = _gen_new_fiber
|
59
|
+
result = @_fiber.resume(block)
|
58
60
|
end
|
59
|
-
result = @_fiber.resume(block)
|
60
61
|
if result.is_a?(Delayer::Deferred::ResultContainer)
|
61
62
|
result
|
62
63
|
else
|
@@ -65,5 +66,13 @@ module Delayer::Deferred
|
|
65
66
|
return result, _fiber
|
66
67
|
end
|
67
68
|
end
|
69
|
+
|
70
|
+
def self._gen_new_fiber
|
71
|
+
Fiber.new do |b|
|
72
|
+
loop do
|
73
|
+
b = Fiber.yield(b.())
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
68
77
|
end
|
69
78
|
end
|
@@ -40,7 +40,7 @@ module Delayer::Deferred
|
|
40
40
|
# Kernel#systemを呼び出して、コマンドが成功たら成功するDeferredを返す。
|
41
41
|
# 失敗した場合、trap{}ブロックには $? の値(Process::Status)か、例外が発生した場合それが渡される
|
42
42
|
# ==== Args
|
43
|
-
# [*args] Kernel#
|
43
|
+
# [*args] Kernel#spawn の引数
|
44
44
|
# ==== Return
|
45
45
|
# Deferred
|
46
46
|
def system(*args)
|
@@ -50,7 +50,7 @@ module Delayer::Deferred
|
|
50
50
|
if status && status.success?
|
51
51
|
status
|
52
52
|
else
|
53
|
-
raise ForeignCommandAborted.new("command aborted: #{args.join(' ')}", process:
|
53
|
+
raise ForeignCommandAborted.new("command aborted: #{args.join(' ')}", process: status) end
|
54
54
|
}
|
55
55
|
end
|
56
56
|
end
|
data/test/deferred_test.rb
CHANGED
@@ -213,6 +213,47 @@ describe(Delayer::Deferred) do
|
|
213
213
|
end
|
214
214
|
end
|
215
215
|
|
216
|
+
describe 'recursive delayer' do
|
217
|
+
it 'Deferred#next call in Deferred.next' do
|
218
|
+
delayer = Delayer.generate_class
|
219
|
+
buf = []
|
220
|
+
erra = errb = errc = nil
|
221
|
+
eval_all_events(delayer) do
|
222
|
+
delayer.Deferred.next{
|
223
|
+
buf << 'begin A'
|
224
|
+
delayer.run
|
225
|
+
buf << 'end A'
|
226
|
+
}.trap{|err|
|
227
|
+
erra = err
|
228
|
+
}
|
229
|
+
delayer.Deferred.next{
|
230
|
+
buf << 'begin B'
|
231
|
+
delayer.run
|
232
|
+
buf << 'end B'
|
233
|
+
}.trap{|err|
|
234
|
+
errb = err
|
235
|
+
}
|
236
|
+
delayer.Deferred.next{
|
237
|
+
buf << 'begin C'
|
238
|
+
delayer.run
|
239
|
+
buf << 'end C'
|
240
|
+
}.trap{|err|
|
241
|
+
errc = err
|
242
|
+
}
|
243
|
+
|
244
|
+
end
|
245
|
+
refute erra
|
246
|
+
refute errb
|
247
|
+
refute errc
|
248
|
+
assert_includes buf, 'begin A'
|
249
|
+
assert_includes buf, 'end A'
|
250
|
+
assert_includes buf, 'begin B'
|
251
|
+
assert_includes buf, 'end B'
|
252
|
+
assert_includes buf, 'begin C'
|
253
|
+
assert_includes buf, 'end C'
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
216
257
|
describe "Deferredable#system" do
|
217
258
|
it "command successed" do
|
218
259
|
succeed = failure = false
|
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: 1.1.
|
4
|
+
version: 1.1.1
|
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-03-
|
11
|
+
date: 2017-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: delayer
|
@@ -86,6 +86,48 @@ dependencies:
|
|
86
86
|
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: guard
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: guard-shell
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: guard-rake
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
89
131
|
description: Deferred for Delayer.
|
90
132
|
email:
|
91
133
|
- toshi.alternative@gmail.com
|