Class: ParallelEach
- Includes:
- Enumerable
- Defined in:
- lib/minitest/parallel_each.rb
Constant Summary collapse
- N =
(ENV['N'] || 2).to_i
Instance Method Summary collapse
- #each ⇒ Object
- #grep(pattern) ⇒ Object
-
#initialize(list) ⇒ ParallelEach
constructor
A new instance of ParallelEach.
Constructor Details
#initialize(list) ⇒ ParallelEach
Returns a new instance of ParallelEach.
7 8 9 10 11 12 |
# File 'lib/minitest/parallel_each.rb', line 7 def initialize list @queue = Queue.new # *sigh*... the Queue api sucks sooo much... list.each { |i| @queue << i } N.times { @queue << nil } end |
Instance Method Details
#each ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/minitest/parallel_each.rb', line 18 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 |
#grep(pattern) ⇒ Object
14 15 16 |
# File 'lib/minitest/parallel_each.rb', line 14 def grep pattern self.class.new super end |