Skip to content

Commit

Permalink
fix return
Browse files Browse the repository at this point in the history
  • Loading branch information
howardchung committed Dec 31, 2024
1 parent 1a64d9d commit 1694593
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions util/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -840,18 +840,21 @@ export async function eachLimitPromise<T>(
let cursor = items.entries();
let numWorkers = limit;
const results = Array(items.length);
let count = 0;
return new Promise(resolve => {
Array(numWorkers).fill('').forEach(async (_, workerIndex) => {
Array(numWorkers).fill('').forEach(async () => {
for (let [i, item] of cursor) {
try {
results[i] = await func(item);
} catch (e) {
// Log exceptions but keep iterating
console.log(e);
}
count += 1;
}
// We'll hit this once per worker, after iteration is complete
if (workerIndex === 0) {
// Only the last one should report results
if (count === items.length) {
resolve(results);
}
});
Expand Down

0 comments on commit 1694593

Please sign in to comment.