DEV Community

Cover image for What Arranged Marriage Taught Me About JavaScript Promises
Shivam Yadav
Shivam Yadav

Posted on

What Arranged Marriage Taught Me About JavaScript Promises

Promises, Rishtas, Aur Thoda Sa Intezaar

Har Indian ghar mein ek phase aata hai.

Shaam ka time.
Mummy chai bana rahi hoti hain.
TV pe daily soap chal raha hota hai.

Image

Aur beech mein casually ek line aati hai

“Beta… Sharma ji ka phone aaya tha.”

Bas.

Background music change.

Aapko samajh aa jaata hai.

Shaadi season officially shuru ho chuka hai.

Riya bhi ussi phase mein thi.

Image

Job stable.
Salary theek.
Life sorted.

Par ghar walon ke hisaab se—

“Ab settle ho jao.”

Aur yahin se shuru hoti hai Promises ki kahani.


Promise Kya Hota Hai?

Promise matlab

“Abhi answer nahi milega.
Par milega.
Ya toh haan mein milega.
Ya seedha mana.”

Beech mein koi confusion nahi.

Jaise rishta.

Ya pakka.
Ya cancel.

JavaScript ne is waiting ko naam diya Promise.


Promise.all() “Sabki Haan Zaroori Hai”

Image

Riya ka pehla rishta aaya.

Ladka achha tha.
Salary impressive thi.
Family decent thi.

Par Indian shaadi emotional nahi hoti.

System hota hai.

Checklist hoti hai.

  • Riya ko ladka pasand?
  • Mummy ko family pasand?
  • Papa ko job pasand?
  • Kundli match?

Sab green tick chahiye.

Ek bhi red cross?

Game over.

Yeh hai Promise.all().

Sab promises successful honge tabhi result milega.

Code

const riya = Promise.resolve("Riya agreed");
const parents = Promise.resolve("Parents agreed");
const horoscope = Promise.resolve("Horoscope matched");

Promise.all([riya, parents, horoscope])
  .then(() => console.log("Shaadi Pakki "))
  .catch(() => console.log("Rishta Toot Gaya "));
Enter fullscreen mode Exit fullscreen mode

Agar ek bhi reject ho jaye…

Sab khatam.


Promise.allSettled() — “Mujhe Sach Batao”

Image

Do teen rishton ke baad Riya badal gayi.

Ab woh toot’ti nahi thi.

Bas bolti thi

“Thik hai. Batao feedback kya hai.”

Ek ne mana kiya.
Ek ne horoscope issue bola.
Ek ne haan bola.

Pehle rejection insult lagta tha.

Ab woh sirf data tha.

Yeh hai Promise.allSettled().

Yeh kehta hai—

Main sabka result launga.
Jo pass hua woh bhi.
Jo fail hua woh bhi.

Code

const boy1 = Promise.resolve("Good Family");
const boy2 = Promise.reject("Horoscope Issue");
const boy3 = Promise.resolve("Nice Nature");

Promise.allSettled([boy1, boy2, boy3])
  .then(result => console.log(result));
Enter fullscreen mode Exit fullscreen mode

Output:

[
 { status: 'fulfilled', value: 'Good Family' },
 { status: 'rejected', reason: 'Horoscope Issue' },
 { status: 'fulfilled', value: 'Nice Nature' }
]
Enter fullscreen mode Exit fullscreen mode

Maturity is when rejection becomes information.


Promise.race() “Jo Pehle Haan Karega”

Image

Ab ghar wale impatient ho gaye.

Dadi ne declare kar diya—

“Jo pehle haan karega, wahi final.”

Do families baat kar rahi thi.

Delhi wale soch rahe the.
Mumbai wale ready ho gaye.

Decision ho gaya.

Yeh hai Promise.race().

Jo pehle settle hua
Wahi result.

Code

const delhi = new Promise(resolve =>
  setTimeout(() => resolve("Delhi Ready"), 2000)
);

const mumbai = new Promise(resolve =>
  setTimeout(() => resolve("Mumbai Ready"), 1000)
);

Promise.race([delhi, mumbai])
  .then(result => console.log(result));
Enter fullscreen mode Exit fullscreen mode

Speed bhi ek decision hoti hai.


Promise.any() “Bas Ek Haan Kaafi Hai”

Image

Phir ek phase aaya.

Jab Riya ne decide kiya

“Mujhe perfect nahi chahiye.”

“Bas ek insaan chahiye jo mujhe choose kare.”

Paanch ne mana kar diya.

Ek ne haan bola.

Aur us ek haan ne
sab purane mana ko irrelevant bana diya.

Yeh hai Promise.any().

Code

const p1 = Promise.reject("Rejected 1");
const p2 = Promise.reject("Rejected 2");
const p3 = Promise.resolve("He Said Yes ❤️");

Promise.any([p1, p2, p3])
  .then(result => console.log(result))
  .catch(() => console.log("Sabne Mana Kar Diya"));
Enter fullscreen mode Exit fullscreen mode

One success is enough.


Promise.resolve() “Instant Haan”

Kabhi kabhi cheezein simple hoti hain.

Milte hi vibe match.

No drama.

Seedha

“Let’s do this.”

Yeh hota hai Promise.resolve().

Code Example

Promise.resolve("Rishta Pakka ")
  .then(result => console.log(result));
Enter fullscreen mode Exit fullscreen mode

Output:

Rishta Pakka 
Enter fullscreen mode Exit fullscreen mode

Immediate success. No waiting.


Promise.reject() “Seedha Mana”

Kabhi kabhi message aata hai

“Sorry. Not interested.”

Bas.

Koi explanation nahi.

Yeh hota hai Promise.reject().

Code Example

Promise.reject("Rishta Cancelled ")
  .catch(error => console.log(error));
Enter fullscreen mode Exit fullscreen mode

Output:

Rishta Cancelled 
Enter fullscreen mode Exit fullscreen mode

Immediate rejection.


The 1% Realization

Zindagi synchronous nahi hoti.

Har cheez time leti hai.

Rishtas.
Career.
Dreams.
Replies.
Results.

Aur har jagah wahi patterns milte hain—

  • Sabka approval → Promise.all()
  • Full report → Promise.allSettled()
  • Jo pehle aaye → Promise.race()
  • Bas ek chance → Promise.any()

Programming sirf syntax nahi hai.

It’s life converted into logic.

Aur jab tum Promises samajh jaate ho…

Tum wait karna seekh jaate ho.

Kyuki intezaar bhi system ka part hai.

Aur jo intezaar samajh gaya…

Woh asynchronous se kabhi nahi darega.

Top comments (0)