parallel 0.4.0 → 0.4.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/README.markdown +1 -0
- data/VERSION +1 -1
- data/lib/parallel.rb +13 -1
- data/parallel.gemspec +9 -3
- data/spec/cases/each_with_index.rb +5 -0
- data/spec/cases/map_with_index.rb +6 -0
- data/spec/cases/map_with_index_empty.rb +6 -0
- data/spec/parallel_spec.rb +16 -0
- metadata +18 -5
data/README.markdown
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
data/lib/parallel.rb
CHANGED
@@ -34,6 +34,10 @@ class Parallel
|
|
34
34
|
array
|
35
35
|
end
|
36
36
|
|
37
|
+
def self.each_with_index(array, options={}, &block)
|
38
|
+
each(array, options.merge(:with_index => true), &block)
|
39
|
+
end
|
40
|
+
|
37
41
|
def self.map(array, options = {})
|
38
42
|
array = array.to_a if array.is_a?(Range)
|
39
43
|
|
@@ -54,13 +58,21 @@ class Parallel
|
|
54
58
|
loop do
|
55
59
|
index = Thread.exclusive{ current+=1 }
|
56
60
|
break if index >= array.size
|
57
|
-
results[index] = *send(method, options.merge(:count => 1))
|
61
|
+
results[index] = *send(method, options.merge(:count => 1)) do
|
62
|
+
args = [array[index]]
|
63
|
+
args << index if options[:with_index]
|
64
|
+
yield *args
|
65
|
+
end
|
58
66
|
end
|
59
67
|
end
|
60
68
|
|
61
69
|
results
|
62
70
|
end
|
63
71
|
|
72
|
+
def self.map_with_index(array, options={}, &block)
|
73
|
+
map(array, options.merge(:with_index => true), &block)
|
74
|
+
end
|
75
|
+
|
64
76
|
def self.processor_count
|
65
77
|
case RUBY_PLATFORM
|
66
78
|
when /darwin/
|
data/parallel.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{parallel}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Grosser"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-04-18}
|
13
13
|
s.email = %q{grosser.michael@gmail.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"README.markdown"
|
@@ -20,6 +20,9 @@ Gem::Specification.new do |s|
|
|
20
20
|
"VERSION",
|
21
21
|
"lib/parallel.rb",
|
22
22
|
"parallel.gemspec",
|
23
|
+
"spec/cases/each_with_index.rb",
|
24
|
+
"spec/cases/map_with_index.rb",
|
25
|
+
"spec/cases/map_with_index_empty.rb",
|
23
26
|
"spec/cases/no_dump_with_each.rb",
|
24
27
|
"spec/cases/parallel_each.rb",
|
25
28
|
"spec/cases/parallel_high_fork_rate.rb",
|
@@ -40,15 +43,18 @@ Gem::Specification.new do |s|
|
|
40
43
|
s.homepage = %q{http://github.com/grosser/parallel}
|
41
44
|
s.rdoc_options = ["--charset=UTF-8"]
|
42
45
|
s.require_paths = ["lib"]
|
43
|
-
s.rubygems_version = %q{1.3.
|
46
|
+
s.rubygems_version = %q{1.3.6}
|
44
47
|
s.summary = %q{Run any kind of code in parallel processes}
|
45
48
|
s.test_files = [
|
46
49
|
"spec/spec_helper.rb",
|
47
50
|
"spec/cases/parallel_with_nil_uses_detected_cpus.rb",
|
51
|
+
"spec/cases/map_with_index_empty.rb",
|
48
52
|
"spec/cases/parallel_map_uneven.rb",
|
49
53
|
"spec/cases/parallel_map_range.rb",
|
54
|
+
"spec/cases/map_with_index.rb",
|
50
55
|
"spec/cases/parallel_with_set_processes.rb",
|
51
56
|
"spec/cases/no_dump_with_each.rb",
|
57
|
+
"spec/cases/each_with_index.rb",
|
52
58
|
"spec/cases/parallel_start_and_kill.rb",
|
53
59
|
"spec/cases/parallel_raise.rb",
|
54
60
|
"spec/cases/parallel_sleeping_2.rb",
|
data/spec/parallel_spec.rb
CHANGED
@@ -102,6 +102,16 @@ describe Parallel do
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
+
describe :map_with_index do
|
106
|
+
it "yields object and index" do
|
107
|
+
`ruby spec/cases/map_with_index.rb 2>&1`.should == 'a0b1'
|
108
|
+
end
|
109
|
+
|
110
|
+
it "does not crash with empty set" do
|
111
|
+
`ruby spec/cases/map_with_index_empty.rb 2>&1`.should == ''
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
105
115
|
describe :each do
|
106
116
|
it "returns original array, works like map" do
|
107
117
|
`ruby spec/cases/parallel_each.rb`.should == '-b--c--d--a-a b c d'
|
@@ -112,6 +122,12 @@ describe Parallel do
|
|
112
122
|
end
|
113
123
|
end
|
114
124
|
|
125
|
+
describe :each_with_index do
|
126
|
+
it "yields object and index" do
|
127
|
+
`ruby spec/cases/each_with_index.rb 2>&1`.should == 'a0b1'
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
115
131
|
describe :in_groups_of do
|
116
132
|
it "works for empty" do
|
117
133
|
Parallel.send(:in_groups_of, [], 3).should == []
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parallel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 4
|
8
|
+
- 1
|
9
|
+
version: 0.4.1
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Michael Grosser
|
@@ -9,7 +14,7 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-04-18 00:00:00 +02:00
|
13
18
|
default_executable:
|
14
19
|
dependencies: []
|
15
20
|
|
@@ -27,6 +32,9 @@ files:
|
|
27
32
|
- VERSION
|
28
33
|
- lib/parallel.rb
|
29
34
|
- parallel.gemspec
|
35
|
+
- spec/cases/each_with_index.rb
|
36
|
+
- spec/cases/map_with_index.rb
|
37
|
+
- spec/cases/map_with_index_empty.rb
|
30
38
|
- spec/cases/no_dump_with_each.rb
|
31
39
|
- spec/cases/parallel_each.rb
|
32
40
|
- spec/cases/parallel_high_fork_rate.rb
|
@@ -56,28 +64,33 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
56
64
|
requirements:
|
57
65
|
- - ">="
|
58
66
|
- !ruby/object:Gem::Version
|
67
|
+
segments:
|
68
|
+
- 0
|
59
69
|
version: "0"
|
60
|
-
version:
|
61
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
71
|
requirements:
|
63
72
|
- - ">="
|
64
73
|
- !ruby/object:Gem::Version
|
74
|
+
segments:
|
75
|
+
- 0
|
65
76
|
version: "0"
|
66
|
-
version:
|
67
77
|
requirements: []
|
68
78
|
|
69
79
|
rubyforge_project:
|
70
|
-
rubygems_version: 1.3.
|
80
|
+
rubygems_version: 1.3.6
|
71
81
|
signing_key:
|
72
82
|
specification_version: 3
|
73
83
|
summary: Run any kind of code in parallel processes
|
74
84
|
test_files:
|
75
85
|
- spec/spec_helper.rb
|
76
86
|
- spec/cases/parallel_with_nil_uses_detected_cpus.rb
|
87
|
+
- spec/cases/map_with_index_empty.rb
|
77
88
|
- spec/cases/parallel_map_uneven.rb
|
78
89
|
- spec/cases/parallel_map_range.rb
|
90
|
+
- spec/cases/map_with_index.rb
|
79
91
|
- spec/cases/parallel_with_set_processes.rb
|
80
92
|
- spec/cases/no_dump_with_each.rb
|
93
|
+
- spec/cases/each_with_index.rb
|
81
94
|
- spec/cases/parallel_start_and_kill.rb
|
82
95
|
- spec/cases/parallel_raise.rb
|
83
96
|
- spec/cases/parallel_sleeping_2.rb
|