Skip to content

Commit

Permalink
lib: reduce overhead of SafePromiseAllSettledReturnVoid calls
Browse files Browse the repository at this point in the history
It was simply calling `SafePromiseAllSettled`, which itself calls
`arrayToSafePromiseIterable` which wraps all promises into new
`SafePromise` object and wraps it into a `SafeArrayIterator`. Since we
don't care about the return value, we can take some shortcuts.

PR-URL: #51243
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
aduh95 authored and richardlau committed Mar 25, 2024
1 parent 9b25268 commit 0a85b0f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/internal/per_context/primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,17 @@ primordials.SafePromiseAllSettled = (promises, mapFn) =>
* @param {(v: T|PromiseLike<T>, k: number) => U|PromiseLike<U>} [mapFn]
* @returns {Promise<void>}
*/
primordials.SafePromiseAllSettledReturnVoid = async (promises, mapFn) => {
await primordials.SafePromiseAllSettled(promises, mapFn);
};
primordials.SafePromiseAllSettledReturnVoid = (promises, mapFn) => new Promise((resolve) => {
let pendingPromises = promises.length;
if (pendingPromises === 0) resolve();
const onSettle = () => {
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), onSettle, onSettle);
}
});

/**
* @template T,U
Expand Down

0 comments on commit 0a85b0f

Please sign in to comment.