class ParallelEach
Provides a parallel each
that lets you enumerate using N
threads. Use environment variable N
to customize. Defaults to 2. Enumerable, so all the goodies come along (tho not all are wrapped yet to return another ParallelEach
instance).
Constants
- N
How many Threads to use for this parallel
each
.
Public Class Methods
new(list)
click to toggle source
Create a new ParallelEach
instance over list
.
# File lib/minitest/parallel_each.rb, line 19 def initialize list @queue = Queue.new # *sigh*... the Queue api sucks sooo much... list.each { |i| @queue << i } N.times { @queue << nil } end
Public Instance Methods
each() { |job| ... }
click to toggle source
Starts N
threads that yield each element to your block. Joins the threads at the end.
# File lib/minitest/parallel_each.rb, line 40 def each threads = N.times.map { Thread.new do Thread.current.abort_on_exception = true while job = @queue.pop yield job end end } threads.map(&:join) end