diff --git a/lib/internal/per_context/primordials.js b/lib/internal/per_context/primordials.js index 5deea076755c9e..140c80566c9e6c 100644 --- a/lib/internal/per_context/primordials.js +++ b/lib/internal/per_context/primordials.js @@ -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); } });