Sha256: 0288e5de409f049b211b32aa653cb94e74ed824fba30fa623b839f0f61562a30
Contents?: true
Size: 1.03 KB
Versions: 2
Compression:
Stored size: 1.03 KB
Contents
# frozen_string_literal: true # TODO: Missing top level documentation! module Cotcube # 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) } 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) end else Parallel.map(chunks, progress: progress, in_processes: processes) do |chunk| Parallel.map(chunk, in_threads: threads, &block) end end end result end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
cotcube-helpers-0.1.5 | lib/cotcube-helpers/parallelize.rb |
cotcube-helpers-0.1.4 | lib/cotcube-helpers/parallelize.rb |