Thursday 15 February 2018

How to run a maximum number of Promises in parallel?

If I retrieve 100 rows from the database, and want to do some async function on all of them, how can I do it and set a maximum? So instead of doing all 100 at the same time, I could specify that I want to do 10 at the same time.How could I pass an array of those 100 Promises and specify that it should do a maximum of 10, so when the first Promise finishes and 9 are in progress, it will get the next one from that array. And if any of the Promises rejects, then the whole thing will stop.Is it a straightforward enough thing that I could program on my own, or would I need some kind of library for this? I'd like to know how to do it on my own for learning purposes, but if it's terribly complex then I guess if you could recommend some libraries for this that would be good too.

Submitted February 15, 2018 at 02:54PM by nowboarding

No comments:

Post a Comment