Skip to content

Commit

Permalink
lib: move function declaration outside of loop
Browse files Browse the repository at this point in the history
PR-URL: #51242
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
  • Loading branch information
sanjaiyan-dev authored and RafaelGSS committed Jan 2, 2024
1 parent 6648a5c commit 8f845eb
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/internal/per_context/primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,14 @@ primordials.SafePromiseAllReturnVoid = (promises, mapFn) =>
new Promise((resolve, reject) => {
let pendingPromises = promises.length;
if (pendingPromises === 0) resolve();
const onFulfilled = () => {
if (--pendingPromises === 0) {
resolve();
}
};
for (let i = 0; i < promises.length; i++) {
const promise = mapFn != null ? mapFn(promises[i], i) : promises[i];
PromisePrototypeThen(PromiseResolve(promise), () => {
if (--pendingPromises === 0) resolve();
}, reject);
PromisePrototypeThen(PromiseResolve(promise), onFulfilled, reject);
}
});

Expand Down

0 comments on commit 8f845eb

Please sign in to comment.