lib/cotcube-helpers/parallelize.rb in cotcube-helpers-0.1.5 vs lib/cotcube-helpers/parallelize.rb in cotcube-helpers-0.1.5.1
- old
+ new
@@ -5,12 +5,12 @@
# TODO: Missing top level documentation!
module Helpers
def parallelize(ary, processes: 1, threads: 1, progress: '', &block)
chunks = []
if [0, 1].include? processes
- result = Parallel.map(ary, in_threads: threads) { |u, &in_thread| in_thread.call(u) }
- elsif [0, 1].include?(threads)
- result = Parallel.map(ary, in_processes: processes) { |u, &in_process| in_process.call(u) }
+ result = Parallel.map(ary, in_threads: threads, &block)
+ elsif [0, 1].include? threads
+ result = Parallel.map(ary, in_processes: processes, &block)
else
ary.each_slice(threads) { |chunk| chunks << chunk }
result = if progress == ''
Parallel.map(chunks, in_processes: processes) do |chunk|
Parallel.map(chunk, in_threads: threads, &block)