Skip to content

Commit

Permalink
Merge pull request #233 from ajlai/fix-modify-options
Browse files Browse the repository at this point in the history
Ensure that .map doesn't modify options passed in
  • Loading branch information
grosser authored Jan 17, 2019
2 parents 7f25128 + 0671afd commit 7332d9f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/parallel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ def each_with_index(array, options={}, &block)
end

def map(source, options = {}, &block)
options = options.dup
options[:mutex] = Mutex.new

if options[:in_processes] && options[:in_threads]
Expand Down
6 changes: 5 additions & 1 deletion spec/parallel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ def cpus
}.should <= 3.5
end

it "does not modify options" do
lambda { Parallel.map([], {}.freeze) }.should_not raise_error
end

it "executes with given parameters" do
`ruby spec/cases/parallel_map.rb`.should == "-a- -b- -c- -d-"
end
Expand All @@ -233,7 +237,7 @@ def cpus
`ruby spec/cases/parallel_map_complex_objects.rb`.should == "YES"
end

it "starts new process imediatly when old exists" do
it "starts new process immediately when old exists" do
time_taken{
`ruby spec/cases/parallel_map_uneven.rb`
}.should <= 3.5
Expand Down

0 comments on commit 7332d9f

Please sign in to comment.