Sha256: abab75713367bf6ae4aa93b79738494c528670071f6d58ca4238d8017bde3b75
Contents?: true
Size: 585 Bytes
Versions: 10
Compression:
Stored size: 585 Bytes
Contents
module Kraps class Parallelizer def self.each(enum, num_threads) queue = Queue.new enum.each { |element| queue.push element } stopped = false threads = Array.new(num_threads) do Thread.new do yield queue.pop(true) until stopped || queue.empty? rescue ThreadError # Queue empty rescue StandardError => e stopped = true e end end threads.each(&:join).each do |thread| raise thread.value if thread.value.is_a?(Exception) end enum end end end
Version data entries
10 entries across 10 versions & 1 rubygems