thread 0.1.5 → 0.1.6
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/thread/pool.rb +12 -7
- data/spec/thread/channel_spec.rb +5 -5
- data/spec/thread/delay_spec.rb +1 -1
- data/spec/thread/every_spec.rb +1 -1
- data/spec/thread/future_spec.rb +4 -4
- data/spec/thread/pipe_spec.rb +5 -5
- data/spec/thread/promise_spec.rb +4 -4
- data/thread.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bd6eca648d0974faadfe04e24cbd3a696f386ba
|
4
|
+
data.tar.gz: f0e27ddf6ed2c9acb872667b3363bb309262aa08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d08f22d5c16219d8829efd68ea170d526e8451c9e2b05f9132b4bfba365c72b4aaad07b517ae14080d13dd3c16e954066fa3d528ef2740566876758c7e17617
|
7
|
+
data.tar.gz: aede26e7afce41766aa3be0031880df21854a02f202cacf1b080754227152e3f6c17342e7374e79052eb2ca6195fe26ac915465fcaaf01c0572d1328dd532422
|
data/lib/thread/pool.rb
CHANGED
@@ -191,20 +191,26 @@ class Thread::Pool
|
|
191
191
|
|
192
192
|
# Are all tasks consumed ?
|
193
193
|
def done?
|
194
|
-
@
|
194
|
+
@mutex.synchronize {
|
195
|
+
@todo.empty? and @waiting == @spawned
|
196
|
+
}
|
195
197
|
end
|
196
198
|
|
197
199
|
# Wait until all tasks are consumed. The caller will be blocked until then.
|
198
200
|
def wait_done
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
201
|
+
loop do
|
202
|
+
@done_mutex.synchronize {
|
203
|
+
return self if done?
|
204
|
+
@done.wait @done_mutex
|
205
|
+
}
|
206
|
+
end
|
203
207
|
end
|
204
208
|
|
205
209
|
# Check if there are idle workers.
|
206
210
|
def idle?
|
207
|
-
@
|
211
|
+
@mutex.synchronize {
|
212
|
+
@todo.length < @waiting
|
213
|
+
}
|
208
214
|
end
|
209
215
|
|
210
216
|
# Process Block when there is a idle worker if not block its returns
|
@@ -221,7 +227,6 @@ class Thread::Pool
|
|
221
227
|
end
|
222
228
|
|
223
229
|
process *args, &block
|
224
|
-
|
225
230
|
end
|
226
231
|
|
227
232
|
# Add a task to the pool which will execute the block with the given
|
data/spec/thread/channel_spec.rb
CHANGED
@@ -6,8 +6,8 @@ describe Thread::Channel do
|
|
6
6
|
ch.send 'lol'
|
7
7
|
ch.send 'wut'
|
8
8
|
|
9
|
-
ch.receive.
|
10
|
-
ch.receive.
|
9
|
+
expect(ch.receive).to eq('lol')
|
10
|
+
expect(ch.receive).to eq('wut')
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'receives with constraints properly' do
|
@@ -15,14 +15,14 @@ describe Thread::Channel do
|
|
15
15
|
ch.send 'lol'
|
16
16
|
ch.send 'wut'
|
17
17
|
|
18
|
-
ch.receive { |v| v == 'wut' }.
|
19
|
-
ch.receive.
|
18
|
+
expect(ch.receive { |v| v == 'wut' }).to eq('wut')
|
19
|
+
expect(ch.receive).to eq('lol')
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'receives nil when using non blocking mode and the channel is empty' do
|
23
23
|
ch = Thread.channel
|
24
24
|
|
25
|
-
ch.receive
|
25
|
+
expect(ch.receive!).to be_nil
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'guards sending properly' do
|
data/spec/thread/delay_spec.rb
CHANGED
data/spec/thread/every_spec.rb
CHANGED
data/spec/thread/future_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe Thread::Future do
|
|
7
7
|
42
|
8
8
|
}
|
9
9
|
|
10
|
-
f.value.
|
10
|
+
expect(f.value).to eq(42)
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'properly checks if anything has been delivered' do
|
@@ -17,9 +17,9 @@ describe Thread::Future do
|
|
17
17
|
42
|
18
18
|
}
|
19
19
|
|
20
|
-
f.delivered
|
20
|
+
expect(f.delivered?).to eq(false)
|
21
21
|
sleep 0.03
|
22
|
-
f.delivered
|
22
|
+
expect(f.delivered?).to eq(true)
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'does not block when a timeout is passed' do
|
@@ -29,6 +29,6 @@ describe Thread::Future do
|
|
29
29
|
42
|
30
30
|
}
|
31
31
|
|
32
|
-
f.value(0).
|
32
|
+
expect(f.value(0)).to be_nil
|
33
33
|
end
|
34
34
|
end
|
data/spec/thread/pipe_spec.rb
CHANGED
@@ -7,17 +7,17 @@ describe Thread::Pipe do
|
|
7
7
|
p << 2
|
8
8
|
p << 4
|
9
9
|
|
10
|
-
p.deq.
|
11
|
-
p.deq.
|
10
|
+
expect(p.deq).to eq(16)
|
11
|
+
expect(p.deq).to eq(32)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'empty works properly' do
|
15
15
|
p = Thread |-> d { sleep 0.02; d * 2 } |-> d { d * 4 }
|
16
16
|
|
17
|
-
p.empty
|
17
|
+
expect(p.empty?).to be(true)
|
18
18
|
p.enq 42
|
19
|
-
p.empty
|
19
|
+
expect(p.empty?).to be(false)
|
20
20
|
p.deq
|
21
|
-
p.empty
|
21
|
+
expect(p.empty?).to be(true)
|
22
22
|
end
|
23
23
|
end
|
data/spec/thread/promise_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe Thread::Promise do
|
|
10
10
|
p << 42
|
11
11
|
}
|
12
12
|
|
13
|
-
p.value.
|
13
|
+
expect(p.value).to eq(42)
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'properly checks if anything has been delivered' do
|
@@ -22,14 +22,14 @@ describe Thread::Promise do
|
|
22
22
|
p << 42
|
23
23
|
}
|
24
24
|
|
25
|
-
p.delivered
|
25
|
+
expect(p.delivered?).to be(false)
|
26
26
|
sleep 0.03
|
27
|
-
p.delivered
|
27
|
+
expect(p.delivered?).to be(true)
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'does not block when a timeout is passed' do
|
31
31
|
p = Thread.promise
|
32
32
|
|
33
|
-
p.value(0).
|
33
|
+
expect(p.value(0)).to be(nil)
|
34
34
|
end
|
35
35
|
end
|
data/thread.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "thread"
|
7
|
-
spec.version = "0.1.
|
7
|
+
spec.version = "0.1.6"
|
8
8
|
spec.authors = ["meh."]
|
9
9
|
spec.email = ["meh@schizofreni.co"]
|
10
10
|
spec.summary = %q{Various extensions to the base thread library.}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thread
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- meh.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|