# Handling Multiple Promises in JavaScript – Promise.all, Promise.race & Promise.any Explained with War Room Analogy

“War room mein decision tab hota hai jab sahi reports sahi time par milti hain…  
Exactly waise hi JavaScript mein async operations handle hote hain.”

## Scene: Modern War Control Room

![](https://cdn.hashnode.com/uploads/covers/69522d7bda0de13bd90a31be/5117170c-7720-4cec-919a-7c4a9903a7ad.jpg align="center")

Border tension chal rahi hai.

HQ ko 3 alag units se update chahiye:

*   Satellite Surveillance
    
*   Drone Strike Unit
    
*   Intelligence Team
    

Teen independent operations.  
Teen lag timing.  
Exactly like **three asynchronous Promises**.

### Step 1: Three Missions = Three Promises

```javascript
const satellite = new Promise((resolve) => {
  setTimeout(() => resolve("Satellite: Enemy Located"), 2000);
});

const drone = new Promise((resolve) => {
  setTimeout(() => resolve("Drone: Target Locked"), 1000);
});

const intel = new Promise((resolve) => {
  setTimeout(() => resolve("Intel: Strategy Ready"), 1500);
});
```

Har unit independently kaam kar rahi hai.  
HQ wait kar raha hai.

### 1\. Promise.all() – Sab Report Aane Do

![](https://cdn.hashnode.com/uploads/covers/69522d7bda0de13bd90a31be/34a40231-e1cf-45f2-a95d-e96f5495e386.jpg align="center")

Commander bolta hai:  
“Jab tak teenon report nahi aati, koi action nahi.”

```javascript
Promise.all([satellite, drone, intel])
  .then((reports) => {
    console.log("All Reports Received:", reports);
    console.log("Commander: Execute Operation");
  })
  .catch((error) => {
    console.log("Mission Failed:", error);
  });
```

### Behavior:

*   Sab fulfill → Operation start
    
*   Ek bhi reject → pura mission fail
    

High dependency = High risk.

### When One Mission Fails

```javascript
const drone = new Promise((resolve, reject) => {
  setTimeout(() => reject("Drone Shot Down"), 1000);
});
```

Ab kya hoga?

`Promise.all()` immediately reject  
Commander: “Abort Mission!”

### 2.Promise.allSettled() – Mujhe Sabka Status Chahiye

![](https://cdn.hashnode.com/uploads/covers/69522d7bda0de13bd90a31be/442f267c-1222-4a7e-8662-0fdfd4e9d29c.jpg align="center")

Kabhi-kabhi HQ ko sabka result chahiye — chahe fail ho ya pass.

```javascript
Promise.allSettled([satellite, drone, intel])
  .then((results) => {
    console.log(results);
  });
```

Output:

```javascript
[
 { status: "fulfilled", value: "Satellite: Enemy Located" },
 { status: "rejected", reason: "Drone Shot Down" },
 { status: "fulfilled", value: "Intel: Strategy Ready" }
]
```

Yeh analysis mode hai.  
Decision baad mein hoga.

### 3.Promise.race() – Jo Pehle Confirm Kare

![](https://cdn.hashnode.com/uploads/covers/69522d7bda0de13bd90a31be/70fa95c8-d1ba-4cc0-8ea5-6e7d3eaf11d1.png align="center")

Emergency situation.  
“Jo pehle confirm karega, uspar action lenge.”

```javascript
Promise.race([satellite, drone, intel])
  .then((fastest) => {
    console.log("Fastest Update:", fastest);
  });
```

Speed matters more than coordination.

### 4.Promise.any() – “Ek Success Kaafi Hai”

```javascript
Promise.any([satellite, drone, intel])
  .then((result) => {
    console.log("At least one success:", result);
  })
  .catch(() => {
    console.log("All missions failed");
  });
```

Behavior:

*   Ek bhi fulfill → Success
    
*   Sab reject → Error
    

Backup strategy activated.

### Async/Await – Clean Command Structure

```javascript
async function warRoom() {
  try {
    const reports = await Promise.all([satellite, drone, intel]);
    console.log("All Clear:", reports);
  } catch (error) {
    console.log("Critical Failure:", error);
  }
}

warRoom();
```

Readable. Structured. Professional.
