functional-ruby 0.6.0 → 0.7.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/README.md +14 -126
- data/lib/functional.rb +4 -1
- data/lib/functional/utilities.rb +46 -0
- data/lib/functional/version.rb +1 -1
- data/lib/functional_ruby.rb +1 -1
- data/md/utilities.md +2 -0
- data/spec/functional/behavior_spec.rb +2 -2
- data/spec/functional/pattern_matching_spec.rb +2 -2
- data/spec/functional/utilities_spec.rb +131 -43
- data/spec/spec_helper.rb +1 -3
- metadata +3 -40
- data/lib/functional/agent.rb +0 -130
- data/lib/functional/all.rb +0 -13
- data/lib/functional/cached_thread_pool.rb +0 -122
- data/lib/functional/concurrency.rb +0 -35
- data/lib/functional/core.rb +0 -2
- data/lib/functional/event.rb +0 -53
- data/lib/functional/event_machine_defer_proxy.rb +0 -23
- data/lib/functional/fixed_thread_pool.rb +0 -89
- data/lib/functional/future.rb +0 -42
- data/lib/functional/global_thread_pool.rb +0 -3
- data/lib/functional/obligation.rb +0 -121
- data/lib/functional/promise.rb +0 -194
- data/lib/functional/thread_pool.rb +0 -61
- data/md/concurrency.md +0 -465
- data/md/future.md +0 -32
- data/md/obligation.md +0 -32
- data/md/promise.md +0 -220
- data/spec/functional/agent_spec.rb +0 -405
- data/spec/functional/cached_thread_pool_spec.rb +0 -112
- data/spec/functional/concurrency_spec.rb +0 -55
- data/spec/functional/event_machine_defer_proxy_spec.rb +0 -246
- data/spec/functional/event_spec.rb +0 -114
- data/spec/functional/fixed_thread_pool_spec.rb +0 -84
- data/spec/functional/future_spec.rb +0 -115
- data/spec/functional/obligation_shared.rb +0 -121
- data/spec/functional/promise_spec.rb +0 -310
- data/spec/functional/thread_pool_shared.rb +0 -209
@@ -1,209 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Functional
|
4
|
-
|
5
|
-
share_examples_for 'Thread Pool' do
|
6
|
-
|
7
|
-
context '#running?' do
|
8
|
-
|
9
|
-
it 'returns true when the thread pool is running' do
|
10
|
-
subject.should be_running
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'returns false when the thread pool is shutting down' do
|
14
|
-
subject.post{ sleep(1) }
|
15
|
-
subject.shutdown
|
16
|
-
subject.should_not be_running
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'returns false when the thread pool is shutdown' do
|
20
|
-
subject.shutdown
|
21
|
-
subject.should_not be_running
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'returns false when the thread pool is killed' do
|
25
|
-
subject.shutdown
|
26
|
-
subject.should_not be_running
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context '#shutdown?' do
|
31
|
-
|
32
|
-
it 'returns true if #shutdown has been called' do
|
33
|
-
subject.shutdown
|
34
|
-
subject.should be_shutdown
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'returns false when running' do
|
38
|
-
subject.should_not be_shutdown
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context '#killed?' do
|
43
|
-
|
44
|
-
it 'returns true if tasks were killed at shutdown' do
|
45
|
-
subject.post{ sleep(1) }
|
46
|
-
subject.kill
|
47
|
-
subject.should be_killed
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'returns false when running' do
|
51
|
-
subject.should_not be_killed
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context '#shutdown' do
|
56
|
-
|
57
|
-
it 'stops accepting new tasks' do
|
58
|
-
subject.post{ sleep(1) }
|
59
|
-
subject.shutdown
|
60
|
-
@expected = false
|
61
|
-
subject.post{ @expected = true }.should be_false
|
62
|
-
sleep(1)
|
63
|
-
@expected.should be_false
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'allows in-progress tasks to complete' do
|
67
|
-
@expected = false
|
68
|
-
subject.post{ sleep(0.5); @expected = true }
|
69
|
-
subject.shutdown
|
70
|
-
sleep(1)
|
71
|
-
@expected.should be_true
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'allows pending tasks to complete' do
|
75
|
-
@expected = false
|
76
|
-
subject.post{ sleep(0.2) }
|
77
|
-
subject.post{ sleep(0.2); @expected = true }
|
78
|
-
subject.shutdown
|
79
|
-
sleep(1)
|
80
|
-
@expected.should be_true
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'allows threads to exit normally' do
|
84
|
-
pool = FixedThreadPool.new(5)
|
85
|
-
pool.shutdown
|
86
|
-
sleep(1)
|
87
|
-
pool.status.should be_empty
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
context '#kill' do
|
92
|
-
|
93
|
-
it 'stops accepting new tasks' do
|
94
|
-
subject.post{ sleep(1) }
|
95
|
-
subject.kill
|
96
|
-
@expected = false
|
97
|
-
subject.post{ @expected = true }.should be_false
|
98
|
-
sleep(1)
|
99
|
-
@expected.should be_false
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'attempts to kill all in-progress tasks' do
|
103
|
-
@expected = false
|
104
|
-
subject.post{ sleep(1); @expected = true }
|
105
|
-
subject.kill
|
106
|
-
sleep(1)
|
107
|
-
@expected.should be_false
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'rejects all pending tasks' do
|
111
|
-
@expected = false
|
112
|
-
subject.post{ sleep(0.5) }
|
113
|
-
subject.post{ sleep(0.5); @expected = true }
|
114
|
-
subject.kill
|
115
|
-
sleep(1)
|
116
|
-
@expected.should be_false
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
context '#wait_for_termination' do
|
121
|
-
|
122
|
-
it 'immediately returns true after shutdown has complete' do
|
123
|
-
subject.shutdown
|
124
|
-
subject.wait_for_termination.should be_true
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'blocks indefinitely when timeout it nil' do
|
128
|
-
subject.post{ sleep(1) }
|
129
|
-
subject.shutdown
|
130
|
-
subject.wait_for_termination(nil).should be_true
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'returns true when shutdown sucessfully completes before timeout' do
|
134
|
-
subject.post{ sleep(0.5) }
|
135
|
-
subject.shutdown
|
136
|
-
subject.wait_for_termination(1).should be_true
|
137
|
-
end
|
138
|
-
|
139
|
-
it 'returns false when shutdown fails to complete before timeout' do
|
140
|
-
subject.post{ sleep(1) }
|
141
|
-
subject.shutdown
|
142
|
-
subject.wait_for_termination(0.5).should be_true
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
context '#post' do
|
147
|
-
|
148
|
-
it 'raises an exception if no block is given' do
|
149
|
-
lambda {
|
150
|
-
subject.post
|
151
|
-
}.should raise_error(ArgumentError)
|
152
|
-
end
|
153
|
-
|
154
|
-
it 'returns true when the block is added to the queue' do
|
155
|
-
subject.post{ nil }.should be_true
|
156
|
-
end
|
157
|
-
|
158
|
-
it 'calls the block with the given arguments' do
|
159
|
-
@expected = nil
|
160
|
-
subject.post(1, 2, 3)do |a, b, c|
|
161
|
-
@expected = a + b + c
|
162
|
-
end
|
163
|
-
sleep(0.1)
|
164
|
-
@expected.should eq 6
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'rejects the block while shutting down' do
|
168
|
-
pool = FixedThreadPool.new(5)
|
169
|
-
pool.post{ sleep(1) }
|
170
|
-
pool.shutdown
|
171
|
-
@expected = nil
|
172
|
-
pool.post(1, 2, 3)do |a, b, c|
|
173
|
-
@expected = a + b + c
|
174
|
-
end
|
175
|
-
@expected.should be_nil
|
176
|
-
end
|
177
|
-
|
178
|
-
it 'returns false while shutting down' do
|
179
|
-
subject.post{ sleep(1) }
|
180
|
-
subject.shutdown
|
181
|
-
subject.post{ nil }.should be_false
|
182
|
-
end
|
183
|
-
|
184
|
-
it 'rejects the block once shutdown' do
|
185
|
-
pool = FixedThreadPool.new(5)
|
186
|
-
pool.shutdown
|
187
|
-
@expected = nil
|
188
|
-
pool.post(1, 2, 3)do |a, b, c|
|
189
|
-
@expected = a + b + c
|
190
|
-
end
|
191
|
-
@expected.should be_nil
|
192
|
-
end
|
193
|
-
|
194
|
-
it 'returns false once shutdown' do
|
195
|
-
subject.post{ nil }
|
196
|
-
subject.shutdown
|
197
|
-
sleep(0.1)
|
198
|
-
subject.post{ nil }.should be_false
|
199
|
-
end
|
200
|
-
|
201
|
-
it 'aliases #<<' do
|
202
|
-
@expected = false
|
203
|
-
subject << proc { @expected = true }
|
204
|
-
sleep(0.1)
|
205
|
-
@expected.should be_true
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end
|
209
|
-
end
|