Handling several promises in Javascript

Let’s say I have an array with a lot of promises. I don’t want to run them in sequence because that would be very slow but I don’t want all of them to run in parallel because that would overload the server. Each of this promises can be resolve or rejected very fast (around 1 second) or, in the worst case scenario, after something around 40 seconds. None of the promises depend on the result of any other. Which is the best way to handle this case? I have seen that an alternative is using Promise.all() in batches of 10 promises. However, the latter doesn’t seem to be efficient considering that I can have 9 promises resolving very fast, but 1 of them resolving very slow. What I would like the following:

Say I have 100 promises. I start processing 10 of them, as soon as one of them resolves, the 11th promise is processed, as soon as other one resolves, the 12th promise is processed, and so on. Notice this behavior is different from using Promise.all() in batches of 10 because in that case the 11th to 20th promise would be processed after all of the 1st to 10th promises are resolved.

Which is the best way of implementing this? I was picturing something like having a queue and having an async function processPromise that pops promises from that queue (until it is empty) and process them. I would then make an array of promises where each promise corresponds to an invocation of processPromise and then Promise.all() over that array. However, I’m not sure if concurrent access to that queue (that is share by different invocations of processPromise) would be an issue, or if I have nothing to worry about considering javascript is single-threaded.