Promise.All batches everything in a single queue. It depends on what you want to do. Simen's approch is an option you can do rate limiting: const maxTaskNum = 8; const unstagedTasks=allTasks.slice(maxTaskNum); const runningTasks = allTasks.slice(0,maxTaskNum); while(runningTasks.length) { const done = await Promis.any(runningTasks); runningTasks.remove(done); doStuff(done) if(unstagedTasks.length) { runningTasks.push(unstagedTasks.pop()); } }
Jeez that's much more complex than the above solutions
meh. it also doesn't make much difference then promiss.all in most cases
using promise.any how do I know which to remove if two tasks potentially have the same data? since remove() doesn't exist on array
Any returns the promise that completed, out of the two, not the data
.splice(i, 1): am I a joke to you?
Yeah since how do i know the index kf the first promise to return from promise.any?
So resolve with the index?
Обсуждают сегодня