Class: ParallelEach
- Includes:
- Enumerable
- Defined in:
- lib/minitest/parallel_each.rb
Overview
This file is imported from the minitest project. DO NOT make modifications in this repo. They will be reverted! File a patch instead and assign it to Ryan Davis.
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.
14 15 16 17 18 19 |
# File 'lib/minitest/parallel_each.rb', line 14 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
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/minitest/parallel_each.rb', line 25 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
21 22 23 |
# File 'lib/minitest/parallel_each.rb', line 21 def grep pattern self.class.new super end |