Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: reduce overhead of SafePromiseAllSettledReturnVoid calls #51243

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/internal/per_context/primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,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) => {
H4ad marked this conversation as resolved.
Show resolved Hide resolved
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
Loading