JP. JP. - 6 months ago 55
Ruby Question

Threading in Ruby with a limit

I have a task I need to perform,

, that will take ~1s each, even while 1 - 10 of them are running in parallel. I need to collect an array of the results for each operation at the end.

If I have 30 stuffs to do, how would I use threading effectively to queue up the
operations so no more than 10 are running concurrently, but the array of results is not given/printed/etc until all (30) tasks have been completed?

I usually have at least some code to try and illustrate what I mean, but with threading I'm at a bit of a loss! Thanks in advance


You need to implement this pattern
This question discusses how that can be done in Ruby