Sha256: 9386210ef65caca3548e347c36474e2c480aed4fc2415a9eab5b69d3caf01502

Contents?: true

Size: 549 Bytes

Versions: 3

Compression:

Stored size: 549 Bytes

Contents

module S3Website
  class Parallelism
    def self.each_in_parallel_or_sequentially(items, &operation)
      if ENV['disable_parallel_processing']
        items.each do |item|
          operation.call item
        end
      else
        items.each_slice(DEFAULT_CONCURRENCY_LEVEL) { |items|
          threads = items.map do |item|
            Thread.new(item) { |item|
              operation.call item
            }
          end
          threads.each(&:join)
        }
      end
    end

    private

    DEFAULT_CONCURRENCY_LEVEL = 100
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
s3_website-1.0.3 lib/s3_website/parallelism.rb
s3_website-1.0.2 lib/s3_website/parallelism.rb
s3_website-1.0.1 lib/s3_website/parallelism.rb