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 richardlau committed Mar 25, 2024
1 parent eef64b7 commit 7b83ef7
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 @@ -540,11 +540,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 7b83ef7

Please sign in to comment.