Sha256: 56c2d3f2da38b50638c8c87b9e6d72c8ae5e80e65c380b8f55667616fa9ea2bf

Contents?: true

Size: 528 Bytes

Versions: 49

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

49 entries across 49 versions & 1 rubygems

Version Path
krane-3.6.2 lib/krane/concurrency.rb
krane-3.6.1 lib/krane/concurrency.rb
krane-3.5.2 lib/krane/concurrency.rb
krane-3.5.1 lib/krane/concurrency.rb
krane-3.5.0 lib/krane/concurrency.rb
krane-3.4.2 lib/krane/concurrency.rb
krane-3.4.1 lib/krane/concurrency.rb
krane-3.4.0 lib/krane/concurrency.rb
krane-3.3.0 lib/krane/concurrency.rb
krane-3.2.0 lib/krane/concurrency.rb
krane-3.1.0 lib/krane/concurrency.rb
krane-3.0.1 lib/krane/concurrency.rb
krane-3.0.0 lib/krane/concurrency.rb
krane-2.4.9 lib/krane/concurrency.rb
krane-2.4.8 lib/krane/concurrency.rb
krane-2.4.7 lib/krane/concurrency.rb
krane-2.4.6 lib/krane/concurrency.rb
krane-2.4.5 lib/krane/concurrency.rb
krane-2.4.4 lib/krane/concurrency.rb
krane-2.4.3 lib/krane/concurrency.rb