Sha256: 56c2d3f2da38b50638c8c87b9e6d72c8ae5e80e65c380b8f55667616fa9ea2bf

Contents?: true

Size: 528 Bytes

Versions: 50

Compression:

Stored size: 528 Bytes

Contents

# frozen_string_literal: true
module Krane
  module Concurrency
    MAX_THREADS = 8

    def self.split_across_threads(all_work, max_threads: MAX_THREADS, &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

50 entries across 50 versions & 1 rubygems

Version Path
krane-2.1.3 lib/krane/concurrency.rb
krane-2.1.2 lib/krane/concurrency.rb
krane-2.1.1 lib/krane/concurrency.rb
krane-2.1.0 lib/krane/concurrency.rb
krane-2.0.0 lib/krane/concurrency.rb
krane-1.1.4 lib/krane/concurrency.rb
krane-1.1.3 lib/krane/concurrency.rb
krane-1.1.2 lib/krane/concurrency.rb
krane-1.1.1 lib/krane/concurrency.rb
krane-1.1.0 lib/krane/concurrency.rb