Method: RMTools.threadify

Defined in:
lib/rmtools/core/threadify.rb

.threadify(ary, max_threads = 4) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/rmtools/core/threadify.rb', line 3

def threadify(ary, max_threads=4)
  forks = []
  ary.each do |e|
    if max_threads > forks.size
      forks << fork { yield e }
    end
    if max_threads == forks.size
      forks.delete Process.wait
    end
  end
  Process.waitall
end