Skip to content

Instantly share code, notes, and snippets.

@davidbarral
Last active July 16, 2024 17:05
Show Gist options
  • Save davidbarral/d0d4da70fa9e6f615595d01f54276e0b to your computer and use it in GitHub Desktop.
Save davidbarral/d0d4da70fa9e6f615595d01f54276e0b to your computer and use it in GitHub Desktop.
allSettled: polyfill
if (!Promise.allSettled) {
Promise.allSettled = promises =>
Promise.all(
promises.map((promise, i) =>
promise
.then(value => ({
status: "fulfilled",
value,
}))
.catch(reason => ({
status: "rejected",
reason,
}))
)
);
}
Promise.allSettled(promises).then(console.log);
@getsnoopy
Copy link

The p in the first line should be capitalized

@davidbarral
Copy link
Author

@getsnoopy Fixed. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment