I have a ruby script array when each element needs processing :
threads = []
elemets.each do |element|
threads.push(Thread.new{process(element)}}
end
threads.each { |aThread| aThread.join }
how ever due to resource limitations, the script works in an optimal way if no more the four elements are processed at a time.
no I know I can dump the each loop and use a variable to count 4 elements and then wait
but is there a cooler ruby way to do it ?
You can enumerate in groups of 4 for an array:
So you can try something like