Sha256: 64b3050da30012d66deeb2a91707ac510f830b4de9357cb882f50661a1577d52
Contents?: true
Size: 502 Bytes
Versions: 8
Compression:
Stored size: 502 Bytes
Contents
# frozen_string_literal: true module Krane module Concurrency MAX_THREADS = 8 def self.split_across_threads(all_work, &block) return if all_work.empty? raise ArgumentError, "Block of work is required" unless block_given? slice_size = ((all_work.length + MAX_THREADS - 1) / MAX_THREADS) threads = [] all_work.each_slice(slice_size) do |work_group| threads << Thread.new { work_group.each(&block) } end threads.each(&:join) end end end
Version data entries
8 entries across 8 versions & 3 rubygems