We want to process data in parallel.
Let's populate source with some data:
source = Queue.new
data = (1..100)
data.each { |e| source << e }
Then create some workers to process data:
(1..16).to_a.map do
Thread.new do
until source.empty?
item = source.pop
sleep 0.5
puts "Processed: #{item}"
end
end
end.map(&:join)