infrastruct 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0113af6fb911302493392efa436bd557868e34a0
4
- data.tar.gz: c8c215e965f2c8793ce42ca92650e30f28127cfa
3
+ metadata.gz: e2813c7d3fd70f85cd9885ac8c0a3100739318c5
4
+ data.tar.gz: 59097900e493e1064d55694c76344a3c588c4384
5
5
  SHA512:
6
- metadata.gz: 208a75436dc546580844be7d284328f1828ed4654cfac6cf53df9000ef609d0cfdf9713f3f1253bfa6e6cde2e2f250e90f54006267c3f7b75e940e7d0880c38d
7
- data.tar.gz: a8eead8fba97d5406e5c1021f1c4c7400a3ceb89355431b82047f37ee3a8f939613447bc0d7a222f08e6917f1a3f4e5540cc7dba7f47426584e9832c71c277fd
6
+ metadata.gz: e5d60b4858af59f4b9bc92e32fb0751232abb2ed04616bbf4a6b85cfa0d5c14d2486b9ea4fa0ed032f467288c77c885de56d9cf998806a4a76ce010fabbf6beb
7
+ data.tar.gz: 05969d1377a42b7bb1baeb9de55141bf320c77942a003f86fded1c4f70a3b4981521373b83ffdf3eb7328ab9acbd8882e97fafac420bcbfb471b56e10816d1c0
@@ -2,18 +2,21 @@ module Infrastruct
2
2
  class Runner
3
3
  def initialize(factory)
4
4
  @factory = factory
5
+ @results = Array.new
6
+ @mutex = Mutex.new
5
7
  end
6
8
 
7
9
  def perform(args)
8
10
  worker = @factory.new
11
+ result = worker.perform(*args)
9
12
 
10
- worker.perform(*args)
13
+ @mutex.synchronize { @results << result }
11
14
  end
12
15
 
13
- def collect(results)
16
+ def collect
14
17
  worker = @factory.new
15
18
 
16
- worker.collect(results)
19
+ @mutex.synchronize { worker.collect(@results) }
17
20
  end
18
21
  end
19
22
  end
@@ -4,7 +4,6 @@ module Infrastruct
4
4
  @runner = runner
5
5
  @number_of_threads = threads
6
6
  @queue = Infrastruct::BlockingQueue.new
7
- @results = Array.new
8
7
  @threads = []
9
8
  end
10
9
 
@@ -16,21 +15,15 @@ module Infrastruct
16
15
  @queue.unblock!
17
16
  @threads.map(&:join)
18
17
 
19
- @runner.collect(@results)
18
+ @runner.collect
20
19
  end
21
20
 
22
21
  def run
23
- mutex = Mutex.new
24
-
25
22
  @threads = @number_of_threads.times.map do |n|
26
23
  Thread.new do
27
24
  begin
28
25
  while args = @queue.pop do
29
- result = @runner.perform(args)
30
-
31
- mutex.synchronize do
32
- @results << result
33
- end
26
+ @runner.perform(args)
34
27
  end
35
28
  rescue ThreadError => error
36
29
  raise error unless error.message == 'queue empty'
@@ -1,3 +1,3 @@
1
1
  module Infrastruct
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infrastruct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Molnar
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-10 00:00:00.000000000 Z
11
+ date: 2016-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler