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 +4 -4
- data/lib/infrastruct/runner.rb +6 -3
- data/lib/infrastruct/thread_pool.rb +2 -9
- data/lib/infrastruct/version.rb +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: e2813c7d3fd70f85cd9885ac8c0a3100739318c5
|
4
|
+
data.tar.gz: 59097900e493e1064d55694c76344a3c588c4384
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5d60b4858af59f4b9bc92e32fb0751232abb2ed04616bbf4a6b85cfa0d5c14d2486b9ea4fa0ed032f467288c77c885de56d9cf998806a4a76ce010fabbf6beb
|
7
|
+
data.tar.gz: 05969d1377a42b7bb1baeb9de55141bf320c77942a003f86fded1c4f70a3b4981521373b83ffdf3eb7328ab9acbd8882e97fafac420bcbfb471b56e10816d1c0
|
data/lib/infrastruct/runner.rb
CHANGED
@@ -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
|
-
|
13
|
+
@mutex.synchronize { @results << result }
|
11
14
|
end
|
12
15
|
|
13
|
-
def collect
|
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
|
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
|
-
|
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'
|
data/lib/infrastruct/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2016-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|