Module: Enumerable
- Defined in:
- lib/parallel_run.rb
Instance Method Summary collapse
Instance Method Details
#_peach_run(pool = nil, &b) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/parallel_run.rb', line 79 def _peach_run(pool = nil, &b) pool ||= count pool = 1 unless pool >= 1 div = (count.to_f/pool.to_f).ceil # should already be integer div = 1 unless div >= 1 # each thread better do something! threads = [] each_slice(div).with_index do |slice, idx| threads << Thread.new(slice) do |thread_slice| yield thread_slice, idx, div end end threads.each{|t| t.join } self end |
#peach(pool = nil, &b) ⇒ Object
95 96 97 98 99 |
# File 'lib/parallel_run.rb', line 95 def peach(pool = nil, &b) _peach_run(pool) do |thread_slice, idx, div| thread_slice.each{|elt| yield elt} end end |