Skip to content

Instantly share code, notes, and snippets.

@Karan-Palan
Created December 22, 2023 05:48
Show Gist options
  • Save Karan-Palan/525632f1b17fde4f3e28b6c65be9fc29 to your computer and use it in GitHub Desktop.
Save Karan-Palan/525632f1b17fde4f3e28b6c65be9fc29 to your computer and use it in GitHub Desktop.
Promise.all (PromiseAPIs)
// Promise.all
const p1 = new Promise((resolve, reject) => {
setTimeout(() => resolve("P1 Sucess"), 3000);
});
const p2 = new Promise((resolve, reject) => {
//setTimeout(() => resolve("P2 Sucess"), 1000);
setTimeout(() => reject("P2 failure"), 1000);
});
const p3 = new Promise((resolve, reject) => {
setTimeout(() => resolve("P3 Sucess"), 2000);
});
Promise.all([p1, p2, p3])
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment