concurrent-ruby 0.3.0.pre.1 → 0.3.0.pre.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -33
- data/lib/concurrent.rb +5 -11
- data/lib/concurrent/{channel.rb → actor.rb} +14 -18
- data/lib/concurrent/agent.rb +5 -4
- data/lib/concurrent/cached_thread_pool.rb +116 -25
- data/lib/concurrent/cached_thread_pool/worker.rb +91 -0
- data/lib/concurrent/event.rb +13 -14
- data/lib/concurrent/event_machine_defer_proxy.rb +0 -1
- data/lib/concurrent/executor.rb +0 -1
- data/lib/concurrent/fixed_thread_pool.rb +111 -14
- data/lib/concurrent/fixed_thread_pool/worker.rb +54 -0
- data/lib/concurrent/future.rb +0 -2
- data/lib/concurrent/global_thread_pool.rb +21 -3
- data/lib/concurrent/goroutine.rb +1 -5
- data/lib/concurrent/obligation.rb +0 -19
- data/lib/concurrent/promise.rb +2 -5
- data/lib/concurrent/runnable.rb +2 -8
- data/lib/concurrent/supervisor.rb +9 -4
- data/lib/concurrent/utilities.rb +24 -0
- data/lib/concurrent/version.rb +1 -1
- data/md/agent.md +3 -3
- data/md/future.md +4 -4
- data/md/promise.md +15 -25
- data/md/thread_pool.md +9 -8
- data/spec/concurrent/actor_spec.rb +377 -0
- data/spec/concurrent/agent_spec.rb +2 -1
- data/spec/concurrent/cached_thread_pool_spec.rb +19 -29
- data/spec/concurrent/event_machine_defer_proxy_spec.rb +1 -1
- data/spec/concurrent/event_spec.rb +1 -1
- data/spec/concurrent/executor_spec.rb +0 -8
- data/spec/concurrent/fixed_thread_pool_spec.rb +27 -16
- data/spec/concurrent/future_spec.rb +0 -13
- data/spec/concurrent/global_thread_pool_spec.rb +73 -0
- data/spec/concurrent/goroutine_spec.rb +0 -15
- data/spec/concurrent/obligation_shared.rb +1 -38
- data/spec/concurrent/promise_spec.rb +28 -47
- data/spec/concurrent/supervisor_spec.rb +1 -2
- data/spec/concurrent/thread_pool_shared.rb +28 -7
- data/spec/concurrent/utilities_spec.rb +50 -0
- data/spec/spec_helper.rb +0 -1
- data/spec/support/functions.rb +17 -0
- metadata +12 -27
- data/lib/concurrent/functions.rb +0 -105
- data/lib/concurrent/null_thread_pool.rb +0 -25
- data/lib/concurrent/thread_pool.rb +0 -149
- data/md/reactor.md +0 -32
- data/spec/concurrent/channel_spec.rb +0 -446
- data/spec/concurrent/functions_spec.rb +0 -197
- data/spec/concurrent/null_thread_pool_spec.rb +0 -78
@@ -1,197 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Concurrent
|
4
|
-
|
5
|
-
describe 'functions' do
|
6
|
-
|
7
|
-
context '#post' do
|
8
|
-
|
9
|
-
it 'calls #post when supported by the object' do
|
10
|
-
object = Class.new{
|
11
|
-
def post() nil; end
|
12
|
-
}.new
|
13
|
-
object.should_receive(:post).with(no_args())
|
14
|
-
post(object){ nil }
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'raises an exception when not supported by the object' do
|
18
|
-
object = Class.new{ }.new
|
19
|
-
lambda {
|
20
|
-
post(object){ nil }
|
21
|
-
}.should raise_error(ArgumentError)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context '#deref' do
|
26
|
-
|
27
|
-
it 'returns the value of the #deref function' do
|
28
|
-
object = Class.new{
|
29
|
-
def deref() nil; end
|
30
|
-
}.new
|
31
|
-
object.should_receive(:deref).with(nil)
|
32
|
-
deref(object, nil){ nil }
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'returns the value of the #value function' do
|
36
|
-
object = Class.new{
|
37
|
-
def value() nil; end
|
38
|
-
}.new
|
39
|
-
object.should_receive(:value).with(nil)
|
40
|
-
deref(object, nil){ nil }
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'raises an exception when not supported by the object' do
|
44
|
-
object = Class.new{ }.new
|
45
|
-
lambda {
|
46
|
-
deref(object, nil){ nil }
|
47
|
-
}.should raise_error(ArgumentError)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context '#pending?' do
|
52
|
-
|
53
|
-
it 'returns the value of the #pending? function' do
|
54
|
-
object = Class.new{
|
55
|
-
def pending?() nil; end
|
56
|
-
}.new
|
57
|
-
object.should_receive(:pending?).with(no_args())
|
58
|
-
pending?(object){ nil }
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'raises an exception when not supported by the object' do
|
62
|
-
object = Class.new{ }.new
|
63
|
-
lambda {
|
64
|
-
pending?(object){ nil }
|
65
|
-
}.should raise_error(ArgumentError)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context '#fulfilled?' do
|
70
|
-
|
71
|
-
it 'returns the value of the #fulfilled? function' do
|
72
|
-
object = Class.new{
|
73
|
-
def fulfilled?() nil; end
|
74
|
-
}.new
|
75
|
-
object.should_receive(:fulfilled?).with(no_args())
|
76
|
-
fulfilled?(object){ nil }
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'returns the value of the #realized? function' do
|
80
|
-
object = Class.new{
|
81
|
-
def realized?() nil; end
|
82
|
-
}.new
|
83
|
-
object.should_receive(:realized?).with(no_args())
|
84
|
-
fulfilled?(object){ nil }
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'raises an exception when not supported by the object' do
|
88
|
-
object = Class.new{ }.new
|
89
|
-
lambda {
|
90
|
-
fulfilled?(object){ nil }
|
91
|
-
}.should raise_error(ArgumentError)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context '#realized?' do
|
96
|
-
|
97
|
-
it 'returns the value of the #realized? function' do
|
98
|
-
object = Class.new{
|
99
|
-
def realized?() nil; end
|
100
|
-
}.new
|
101
|
-
object.should_receive(:realized?).with(no_args())
|
102
|
-
realized?(object){ nil }
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'returns the value of the #fulfilled? function' do
|
106
|
-
object = Class.new{
|
107
|
-
def fulfilled?() nil; end
|
108
|
-
}.new
|
109
|
-
object.should_receive(:fulfilled?).with(no_args())
|
110
|
-
realized?(object){ nil }
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'raises an exception when not supported by the object' do
|
114
|
-
object = Class.new{ }.new
|
115
|
-
lambda {
|
116
|
-
realized?(object){ nil }
|
117
|
-
}.should raise_error(ArgumentError)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
context '#rejected?' do
|
122
|
-
|
123
|
-
it 'returns the value of the #rejected? function' do
|
124
|
-
object = Class.new{
|
125
|
-
def rejected?() nil; end
|
126
|
-
}.new
|
127
|
-
object.should_receive(:rejected?).with(no_args())
|
128
|
-
rejected?(object){ nil }
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'raises an exception when not supported by the object' do
|
132
|
-
object = Class.new{ }.new
|
133
|
-
lambda {
|
134
|
-
rejected?(object){ nil }
|
135
|
-
}.should raise_error(ArgumentError)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
describe Agent do
|
141
|
-
|
142
|
-
before(:each) do
|
143
|
-
Agent.thread_pool = FixedThreadPool.new(1)
|
144
|
-
end
|
145
|
-
|
146
|
-
it 'aliases #<< for Agent#post' do
|
147
|
-
subject = Agent.new(0)
|
148
|
-
subject << proc{ 100 }
|
149
|
-
sleep(0.1)
|
150
|
-
subject.value.should eq 100
|
151
|
-
end
|
152
|
-
|
153
|
-
it 'aliases Kernel#agent for Agent.new' do
|
154
|
-
agent(10).should be_a(Agent)
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'aliases Kernel#deref for #deref' do
|
158
|
-
deref(Agent.new(10)).should eq 10
|
159
|
-
deref(Agent.new(10), 10).should eq 10
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'aliases Kernel:post for Agent#post' do
|
163
|
-
subject = Agent.new(0)
|
164
|
-
post(subject){ 100 }
|
165
|
-
sleep(0.1)
|
166
|
-
subject.value.should eq 100
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
describe Future do
|
171
|
-
|
172
|
-
before(:each) do
|
173
|
-
Future.thread_pool = FixedThreadPool.new(1)
|
174
|
-
end
|
175
|
-
|
176
|
-
it 'aliases Kernel#future for Future.new' do
|
177
|
-
future().should be_a(Future)
|
178
|
-
future(){ nil }.should be_a(Future)
|
179
|
-
future(1, 2, 3).should be_a(Future)
|
180
|
-
future(1, 2, 3){ nil }.should be_a(Future)
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
describe Promise do
|
185
|
-
|
186
|
-
before(:each) do
|
187
|
-
Promise.thread_pool = FixedThreadPool.new(1)
|
188
|
-
end
|
189
|
-
|
190
|
-
it 'aliases Kernel#promise for Promise.new' do
|
191
|
-
promise().should be_a(Promise)
|
192
|
-
promise(){ nil }.should be_a(Promise)
|
193
|
-
promise(1, 2, 3).should be_a(Promise)
|
194
|
-
promise(1, 2, 3){ nil }.should be_a(Promise)
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'concurrent/goroutine'
|
4
|
-
|
5
|
-
module Concurrent
|
6
|
-
|
7
|
-
describe NullThreadPool do
|
8
|
-
|
9
|
-
subject { NullThreadPool.new }
|
10
|
-
|
11
|
-
after(:all) do
|
12
|
-
$GLOBAL_THREAD_POOL = FixedThreadPool.new(1)
|
13
|
-
end
|
14
|
-
|
15
|
-
context '#post' do
|
16
|
-
|
17
|
-
it 'creates a new thread for a call without arguments' do
|
18
|
-
thread = Thread.new{ nil }
|
19
|
-
Thread.should_receive(:new).with(no_args()).and_return(thread)
|
20
|
-
$GLOBAL_THREAD_POOL.should_not_receive(:post).with(any_args())
|
21
|
-
subject.post{ nil }
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'executes a call without arguments' do
|
25
|
-
@expected = false
|
26
|
-
subject.post{ @expected = true }
|
27
|
-
sleep(0.1)
|
28
|
-
@expected.should be_true
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'creates a new thread for a call with arguments' do
|
32
|
-
thread = Thread.new{ nil }
|
33
|
-
Thread.should_receive(:new).with(1,2,3).and_return(thread)
|
34
|
-
$GLOBAL_THREAD_POOL.should_not_receive(:post).with(any_args())
|
35
|
-
subject.post(1,2,3){ nil }
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'executes a call with one argument' do
|
39
|
-
@expected = 0
|
40
|
-
subject.post(1){|one| @expected = one }
|
41
|
-
sleep(0.1)
|
42
|
-
@expected.should == 1
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'executes a call with multiple arguments' do
|
46
|
-
@expected = nil
|
47
|
-
subject.post(1,2,3,4,5){|*args| @expected = args }
|
48
|
-
sleep(0.1)
|
49
|
-
@expected.should eq [1,2,3,4,5]
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'aliases #<<' do
|
53
|
-
thread = Thread.new{ nil }
|
54
|
-
Thread.should_receive(:new).with(no_args()).and_return(thread)
|
55
|
-
$GLOBAL_THREAD_POOL.should_not_receive(:post).with(any_args())
|
56
|
-
subject << proc{ nil }
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'operation' do
|
61
|
-
|
62
|
-
context 'goroutine' do
|
63
|
-
|
64
|
-
it 'gets a new thread' do
|
65
|
-
$GLOBAL_THREAD_POOL = subject
|
66
|
-
|
67
|
-
t = Thread.new{ nil }
|
68
|
-
|
69
|
-
Thread.should_receive(:new).with(no_args()).and_return(t)
|
70
|
-
go{ nil }
|
71
|
-
|
72
|
-
Thread.should_receive(:new).with(1,2,3).and_return(t)
|
73
|
-
go(1,2,3){ nil }
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|