obligation 0.1.0 → 0.2.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 +4 -4
- data/lib/obligation/impl.rb +13 -5
- data/lib/obligation/version.rb +1 -1
- data/spec/thread/then_spec.rb +22 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75787eca2f213420d4c1cbba32bd32d795c453cb
|
4
|
+
data.tar.gz: 6905d797f235dad221db7aed8ff57bb2758300de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c1a7c03fbd6d2f9cf26a1886fb1551c9b747fd2be951ac8a9407e7b3a21e8729d90ac25d54bb56e6e9123949092312eab90bf2e3b78d2b3f552febd7abd22b6
|
7
|
+
data.tar.gz: 8f724da6545978f9d9aa15ea36c746cd16d58208afb567f14bf5f3753e7f7253d2f583fd9c176b1dba1872b2309ba07a1a86e8fbae8a94781a0d665fc5c26c9a
|
data/lib/obligation/impl.rb
CHANGED
@@ -131,11 +131,7 @@ module Obligation
|
|
131
131
|
@mutex.synchronize do
|
132
132
|
if _sync_pending?
|
133
133
|
begin
|
134
|
-
|
135
|
-
_sync_fulfill @block.call @dependencies.map(&:value)
|
136
|
-
else
|
137
|
-
_sync_fulfill @block.call @dependencies.value
|
138
|
-
end
|
134
|
+
_sync_fulfill _nested @block.call _resolved_dependencies
|
139
135
|
rescue RejectedError => e
|
140
136
|
_sync_reject e.cause
|
141
137
|
raise RejectedError.new "Obligation rejected due to #{e.cause}."
|
@@ -149,6 +145,18 @@ module Obligation
|
|
149
145
|
end
|
150
146
|
end
|
151
147
|
end
|
148
|
+
|
149
|
+
def _resolved_dependencies
|
150
|
+
return @dependencies.map(&:value) if @dependencies.is_a?(Array)
|
151
|
+
|
152
|
+
@dependencies.value
|
153
|
+
end
|
154
|
+
|
155
|
+
def _nested(result)
|
156
|
+
return result.value if result.respond_to? :value
|
157
|
+
|
158
|
+
result
|
159
|
+
end
|
152
160
|
end
|
153
161
|
|
154
162
|
#
|
data/lib/obligation/version.rb
CHANGED
data/spec/thread/then_spec.rb
CHANGED
@@ -26,6 +26,28 @@ describe Obligation do
|
|
26
26
|
expect(result).to eq 1337
|
27
27
|
end
|
28
28
|
|
29
|
+
it 'should return nested obligations' do
|
30
|
+
o1 = Obligation.create do |w|
|
31
|
+
Thread.new do
|
32
|
+
sleep 0.2
|
33
|
+
w.fulfill 42
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
o2 = o1.then do
|
38
|
+
Obligation.create do |r|
|
39
|
+
Thread.new do
|
40
|
+
sleep 0.2
|
41
|
+
r.fulfill 57
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
result = o2.value
|
47
|
+
|
48
|
+
expect(result).to eq 57
|
49
|
+
end
|
50
|
+
|
29
51
|
it 'should inherit error on reject' do
|
30
52
|
o1 = Obligation.create do |w|
|
31
53
|
Thread.new do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: obligation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Graichen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
75
|
version: '0'
|
76
76
|
requirements: []
|
77
77
|
rubyforge_project:
|
78
|
-
rubygems_version: 2.
|
78
|
+
rubygems_version: 2.4.8
|
79
79
|
signing_key:
|
80
80
|
specification_version: 4
|
81
81
|
summary: Support library to provide Futures and Promises for different concurrency
|
@@ -84,3 +84,4 @@ test_files:
|
|
84
84
|
- spec/spec_helper.rb
|
85
85
|
- spec/thread/then_spec.rb
|
86
86
|
- spec/thread/value_spec.rb
|
87
|
+
has_rdoc:
|