1
This commit is contained in:
@@ -1,26 +1,3 @@
|
||||
export async function sleep_ms(ms) {
|
||||
await new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
export async function map_limit(items, worker) {
|
||||
const list = Array.isArray(items) ? items : [];
|
||||
|
||||
const res = new Array(list.length);
|
||||
let idx = 0;
|
||||
|
||||
async function run_one() {
|
||||
while (idx < list.length) {
|
||||
const cur = idx;
|
||||
idx += 1;
|
||||
res[cur] = await worker(list[cur], cur);
|
||||
}
|
||||
}
|
||||
|
||||
const runners = [];
|
||||
for (let i = 0; i < list.length; i += 1) {
|
||||
runners.push(run_one());
|
||||
}
|
||||
|
||||
await Promise.all(runners);
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user