thread 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19359ceb19e36b411191f6a1ad561f7d1d4494b1
4
- data.tar.gz: 26aa332d8178f937334fb00c01b6d52767aa0164
3
+ metadata.gz: 6bd6eca648d0974faadfe04e24cbd3a696f386ba
4
+ data.tar.gz: f0e27ddf6ed2c9acb872667b3363bb309262aa08
5
5
  SHA512:
6
- metadata.gz: 53b93154104816e06c93c0b4477aa1a65ebc9c878b9e8723881ccf3ea5e2f9ab41c8454b6889018fb0132e9ece4c6efcac3731bff77a987629f4e784ce9d9bfc
7
- data.tar.gz: 8cd976ebd6c34ac6b0d62facda8da94d67e9fda638f4a62a1d0693c12742ac1a2afca100d4c330de3638a4ea79155c3b08afb01ab1e2ef659365da16f74e9ff9
6
+ metadata.gz: 4d08f22d5c16219d8829efd68ea170d526e8451c9e2b05f9132b4bfba365c72b4aaad07b517ae14080d13dd3c16e954066fa3d528ef2740566876758c7e17617
7
+ data.tar.gz: aede26e7afce41766aa3be0031880df21854a02f202cacf1b080754227152e3f6c17342e7374e79052eb2ca6195fe26ac915465fcaaf01c0572d1328dd532422
@@ -191,20 +191,26 @@ class Thread::Pool
191
191
 
192
192
  # Are all tasks consumed ?
193
193
  def done?
194
- @todo.empty? and @waiting == @spawned
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
- @done_mutex.synchronize {
200
- return if done?
201
- @done.wait @done_mutex
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
- @todo.length < @waiting
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
@@ -6,8 +6,8 @@ describe Thread::Channel do
6
6
  ch.send 'lol'
7
7
  ch.send 'wut'
8
8
 
9
- ch.receive.should == 'lol'
10
- ch.receive.should == 'wut'
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' }.should == 'wut'
19
- ch.receive.should == 'lol'
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!.should == nil
25
+ expect(ch.receive!).to be_nil
26
26
  end
27
27
 
28
28
  it 'guards sending properly' do
@@ -6,6 +6,6 @@ describe Thread::Delay do
6
6
  42
7
7
  }
8
8
 
9
- d.value.should == 42
9
+ expect(d.value).to eq(42)
10
10
  end
11
11
  end
@@ -4,6 +4,6 @@ describe Thread::Every do
4
4
  it 'delivers a value properly' do
5
5
  e = Thread.every(5) { sleep 0.02; 42 }
6
6
 
7
- e.value.should == 42
7
+ expect(e.value).to eq(42)
8
8
  end
9
9
  end
@@ -7,7 +7,7 @@ describe Thread::Future do
7
7
  42
8
8
  }
9
9
 
10
- f.value.should == 42
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?.should == false
20
+ expect(f.delivered?).to eq(false)
21
21
  sleep 0.03
22
- f.delivered?.should == true
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).should == nil
32
+ expect(f.value(0)).to be_nil
33
33
  end
34
34
  end
@@ -7,17 +7,17 @@ describe Thread::Pipe do
7
7
  p << 2
8
8
  p << 4
9
9
 
10
- p.deq.should == 16
11
- p.deq.should == 32
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?.should == true
17
+ expect(p.empty?).to be(true)
18
18
  p.enq 42
19
- p.empty?.should == false
19
+ expect(p.empty?).to be(false)
20
20
  p.deq
21
- p.empty?.should == true
21
+ expect(p.empty?).to be(true)
22
22
  end
23
23
  end
@@ -10,7 +10,7 @@ describe Thread::Promise do
10
10
  p << 42
11
11
  }
12
12
 
13
- p.value.should == 42
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?.should == false
25
+ expect(p.delivered?).to be(false)
26
26
  sleep 0.03
27
- p.delivered?.should == true
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).should == nil
33
+ expect(p.value(0)).to be(nil)
34
34
  end
35
35
  end
@@ -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.5"
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.5
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-02-13 00:00:00.000000000 Z
11
+ date: 2015-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec