Sitemap
Imrounakshaw

Imrounakshaw

Promises:-

3 min readFeb 28, 2026

--

In JS, Promise is a Future Result of some Work, Which doesn’t exist right now, but will come later — or will fail.

Example:-You ordered a pizza from Domino’s……Domino’s said: “Sir, delivery in 30 mins — That’s a promise! — There would be a Delay or Even the order got Cancelled due to some Reasons …

. Promise Method :-

Set a Scene here ,First:-

Consider Your Wedding is Fix !(Unlike Piyush sir).

Get Imrounakshaw’s stories in your inbox

Join Medium for free to get updates from this writer.

Your mom gave 3 tasks to 3 different people :-

.Chef — cook the food

.DJ — get the music ready

.Decorator — decorate the hall

— First — Create the Promises:-

const chef = new Promise((resolve, reject) => {
setTimeout(() => resolve("Food is ready!"), 2000);
});
const dj = new Promise((resolve, reject) => {
setTimeout(() => reject(" DJ fell sick!"), 2000);
});
const decorator = new Promise((resolve, reject) => {
setTimeout(() => resolve("Hall is decorated!"), 2000);
});

1.Promise.all ( ) — All 3 Must Run ..!

Story: Your mom said — “If ALL THREE tasks are not done ,We have to Call off the wedding !”

Promise.all([chef, dj, decorator])
.then((results) => {
console.log(" Wedding starts!", results);
})
.catch((error) => {
console.log(" Wedding cancelled!", error);
});
// Output:
// Wedding cancelled! As ,DJ fell sick!

Remember:-

  • All succeed → .then() runs.
  • Even ONE fails → jumps to .catch() immediately — doesn't even wait for others.

2. Promise.allSettled ( ) :-

  • Give Report of full Chaos .Like, in this Scene First Tell Me Who Came, Who Didn’t..
  • story: Your dad said — “First bring me the full report — who is ready, who is not. Then we’ll decide!”
Promise.allSettled([chef, dj, decorator])
.then((results) => {
results.forEach((result) => {
if (result.status === "fulfilled") {
console.log(" Done:", result.value);
} else {
console.log(" Failed:", result.reason);
}
});
});
// Output:
// Done: Food is ready!i.e, Fulfilled
// Failed: DJ fell sick!i.e, Rejected
// Done: Hall is decorated!i.e, Fulfilled

Remember:

  • If any Condition get fails .catch() never runs.
  • You get the Status of every single condition — fulfilled or rejected.
  • waits for all to complete before giving results.

3.Promise.any ( ):-

Anyone Can showed up.

Story : DJ didn’t come, so what! Right now , we can called 3 new DJs — “Whoever comes first, we’ll hire them!”

const dj1 = new Promise(( reject) =>
setTimeout(() => reject(" DJ1 is busy"), 2000)
);
const dj2 = new Promise((resolve) =>
setTimeout(() => resolve("DJ2 is here!"), 1000) // fastest!
);
const dj3 = new Promise(( reject) =>
setTimeout(() => reject("DJ3 can't come"), 2000)
);
Promise.any([dj1, dj2, dj3])
.then((result) => {
console.log(" Got a DJ:", result);
})
.catch(() => {
console.log(" No DJ showed up!");
});
// Output:
// Got a DJ: DJ2 is here!
```
**Remember:**
- **First successful** one → `.then()` runs immediately
- Doesn't wait for the rest
- Only goes to `.catch()` if # ALL of them fail
---
## Final Picture
```
Promise.all → ALL must come, only then wedding happens (Strict Mom )
Promise.allSettled → Give me everyone's status report (Wise Dad )
Promise.any → Anyone just please show up! (Chill Friend )

.Brief View:-

. Promise.all() :- All must Succeeds, its rejects if anyone will be fails .

. Promise.allSettled () :- All get easily Succeeds, there would be no rejection ,Never.

. Promise.any() :- Anyone Succeeds can works, its rejects if Allwill be fails .

--

--