Ruby Language Queue Multiple Workers One Sink

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!


We want to gather data created by multiple Workers.

First we create a Queue:

sink =

Then 16 workers all generating a random number and pushing it into sink:

(1..16) do do
    sink << rand(1..100)

And to get the data, convert a Queue to an Array:

data = [].tap { |a| a << sink.pop until sink.empty? }

Got any Ruby Language Question?