forkandreturn 0.2.0 → 0.2.1
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.
- data/CHANGELOG +6 -0
- data/VERSION +1 -1
- data/lib/forkandreturn/enumerable.rb +3 -25
- data/test/test.rb +0 -1
- metadata +4 -4
data/CHANGELOG
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
@@ -23,7 +23,7 @@ module Enumerable
|
|
23
23
|
# concurrent_collect() is suitable for handling a couple of very CPU intensive jobs, like parsing large XML files.
|
24
24
|
|
25
25
|
def concurrent_collect(max_concurrent_workers=-1, &block)
|
26
|
-
max_concurrent_workers = 0 unless ForkAndReturn::Util.
|
26
|
+
max_concurrent_workers = 0 unless ForkAndReturn::Util.forkable?
|
27
27
|
|
28
28
|
case
|
29
29
|
when max_concurrent_workers < 0 # No limit.
|
@@ -69,34 +69,12 @@ module Enumerable
|
|
69
69
|
# clustered_concurrent_collect() is suitable for handling a lot of not too CPU intensive jobs.
|
70
70
|
|
71
71
|
def clustered_concurrent_collect(number_of_clusters=ForkAndReturn::Util.cores, &block)
|
72
|
-
number_of_clusters = 0 unless ForkAndReturn::Util.
|
72
|
+
number_of_clusters = 0 unless ForkAndReturn::Util.forkable?
|
73
73
|
|
74
74
|
if number_of_clusters < 1
|
75
75
|
self.concurrent_collect(number_of_clusters, &block)
|
76
76
|
else
|
77
|
-
|
78
|
-
last_pos = -1
|
79
|
-
res = []
|
80
|
-
|
81
|
-
self.each do |object|
|
82
|
-
last_pos += 1
|
83
|
-
|
84
|
-
(clusters[last_pos%number_of_clusters] ||= []) << object
|
85
|
-
end
|
86
|
-
|
87
|
-
clusters.concurrent_collect(-1) do |cluster|
|
88
|
-
cluster.collect do |object|
|
89
|
-
if block.arity > 1 and object.kind_of?(Enumerable)
|
90
|
-
yield(*object.to_a)
|
91
|
-
else
|
92
|
-
yield(object)
|
93
|
-
end
|
94
|
-
end + (cluster.length == clusters[0].length ? [] : [nil]) # Add padding nil, in order to be able to transpose
|
95
|
-
end.transpose.each do |array|
|
96
|
-
res.concat(array)
|
97
|
-
end
|
98
|
-
|
99
|
-
res[0..last_pos] # Remove padding nil.
|
77
|
+
ThreadLimiter.handle_clusters(self, number_of_clusters, :concurrent_collect, &block)
|
100
78
|
end
|
101
79
|
end
|
102
80
|
|
data/test/test.rb
CHANGED
@@ -232,7 +232,6 @@ class ForkAndReturnEnumerableTest < Test::Unit::TestCase
|
|
232
232
|
result = data.collect(&block)
|
233
233
|
|
234
234
|
assert_equal(3, data.clustered_concurrent_collect(3, &block).sort.uniq.length)
|
235
|
-
|
236
235
|
assert_equal(result, data.clustered_concurrent_collect(0, &block))
|
237
236
|
assert_not_equal(result, data.clustered_concurrent_collect(3, &block))
|
238
237
|
assert_not_equal(result, data.clustered_concurrent_collect(-1, &block))
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forkandreturn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erik Veenstra
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-10-06 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
23
|
+
version: 0.1.2
|
24
24
|
version:
|
25
25
|
description: Runs a block of code in a seperate process and collects the result later. Includes a lot of convenient methods on Enumerable.
|
26
26
|
email: forkandreturn@erikveen.dds.nl
|
@@ -52,7 +52,7 @@ rdoc_options:
|
|
52
52
|
- CHANGELOG
|
53
53
|
- example.txt
|
54
54
|
- --title
|
55
|
-
- forkandreturn (0.2.
|
55
|
+
- forkandreturn (0.2.1)
|
56
56
|
- --main
|
57
57
|
- README
|
58
58
|
require_paths:
|