Skip to content

Instantly share code, notes, and snippets.

@szaranger
Created July 19, 2022 11:52
Show Gist options
  • Save szaranger/f0952907edd6697a3e302fbd468816bb to your computer and use it in GitHub Desktop.
Save szaranger/f0952907edd6697a3e302fbd468816bb to your computer and use it in GitHub Desktop.
async function run() {
const settledPromises = Promise.allSettled([
new Promise((resolve) => setTimeout(() => resolve(["shirts", "trousers"]), 800)),
new Promise((resolve) => setTimeout(() => resolve(["sneakers", "boots"]), 800)),
]);
// wait...
const promises = await settledPromises;
// after 0.8 seconds
console.log(promises);
/*
[[object Object] {
status: "fulfilled",
value: ["shirts", "trousers"]
}, [object Object] {
status: "fulfilled",
value: ["sneakers", "boots"]
}]
*/
}
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment