Похожие чаты

Anyone have a nice solution to chunked/batched promise.all?

9 ответов

17 просмотров

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()); } }

Avihay B
Promise.All batches everything in a single queue. ...

Jeez that's much more complex than the above solutions

Thomas
Jeez that's much more complex than the above solut...

meh. it also doesn't make much difference then promiss.all in most cases

LKD70-🇬🇧 Автор вопроса
Avihay B
Promise.All batches everything in a single queue. ...

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

LKD70 🇬🇧
using promise.any how do I know which to remove if...

Any returns the promise that completed, out of the two, not the data

LKD70-🇬🇧 Автор вопроса
Thomas
.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?

LKD70-🇬🇧 Автор вопроса
Thomas
Wrap them

So resolve with the index?

Похожие вопросы

Обсуждают сегодня

Карта сайта