Skip to main content

Command Palette

Search for a command to run...

JavaScript Promise Static Methods Explained Using an ISRO Rocket Launch Analogy

Updated
7 min read
JavaScript Promise Static Methods Explained Using an ISRO Rocket Launch Analogy

What do JavaScript Promises and an ISRO rocket launch have in common?

At first glance — nothing. But if you think about it, both involve:

  • Multiple independent systems

  • Uncertainty

  • Timing

  • Success or failure

  • Careful coordination

Before we step into Sriharikota, let’s understand what a Promise actually is.


🌑 What is a Promise in JavaScript?

A Promise is an object in JavaScript that represents the outcome of an asynchronous operation — either its success or its failure.

In simple terms:

When JavaScript starts a task that takes time (API request, database query, file read, timer), it immediately returns a Promise that says:

“I’ll give you the result later — success or error.”


🌕 Three Things to Know About Promises

1 ) Creation

Promises are created using new Promise():

const mission = new Promise((resolve, reject) => {
  const success = true;

  if (success) {
    resolve("Mission Successful");
  } else {
    reject("Mission Failed");
  }
});

// If success = true:
// → State: Fulfilled
// → Value: "Mission Successful"

// If success = false:
// → State: Rejected
// → Reason: "Mission Failed"

2 ) Handling

We handle Promises using:

  • .then() → for success

  • .catch() → for failure

mission
  .then(result => console.log("Success:", result))   // Success: Mission Successful
  .catch(error => console.log("Error:", error));

Even if resolve() runs immediately, .then() executes asynchronously via the microtask queue.


3 ) Chaining

Promises allow sequential asynchronous execution:

function fetchData() {
  return Promise.resolve("Raw Data");
}

function processData(data) {
  return data + " → Processed";
}

function saveData(processed) {
  return processed + " → Saved";
}

fetchData()
  .then(data => processData(data))
  .then(processed => saveData(processed))
  .then(finalResult => console.log(finalResult))  
  // Output: Raw Data → Processed → Saved
  .catch(error => console.error(error));

No callback hell. Clean flow.


🌕Promise States

Every Promise has three states:

  1. Pending

  2. Fulfilled

  3. Rejected

Once fulfilled or rejected, it cannot change state.


Now let’s imagine something bigger. What if ISRO used JavaScript Promises to coordinate a rocket launch?

Let’s go to Sriharikota...🏃🏻‍♀️‍➡️🏃🏻‍♂️‍➡️


🌕 The ISRO Launch Scenario

ISRO is preparing a PSLV launch.

In launching program multiple systems are operating simultaneously:

  • Fuel loading

  • Weather monitoring

  • Navigation calibration

  • Communication channels

  • Heat sensors

Each system behaves like a Promise.

Each one will eventually:

  • Succeed

  • Fail

  • Or still be processing

Now let's see how we can simulate promise methods with ISRO's rocket launching program.


1 ) Promise.resolve() — “Mission Successful”

The satellite has already entered orbit. Now Mission Control announces: “Satellite successfully deployed. Sab safe hai.” No waiting required.

Technical Meaning

Promise.resolve(value) returns a Promise that is immediately fulfilled with the provided value.

const mission = Promise.resolve("Satellite successfully deployed");

mission.then(result => {
  console.log("ISRO Update:", result);
});
// Output: ISRO Update: Satellite successfully deployed

Even though it resolves instantly, .then() still runs asynchronously.


2 ) Promise.reject() — “Launch Aborted”

Countdown begins.....T-5… T-4…Cryogenic engine failure detected!!

Mission Control: “Launch aborted.”

Technical Meaning

Promise.reject(reason) creates a Promise that is immediately rejected.

const failure = Promise.reject("Cryogenic engine failure");

failure
  .then(() => console.log("Launch started"))
  .catch(error => console.log("ISRO Alert:", error));
// Output: ISRO Alert: Cryogenic engine failure

Rejections propagate down the chain until handled.


3 ) Promise.all() — “All Systems Green”

Before launch Mission Control checjks :

  • Fuel ready?

  • Weather clear?

  • Navigation calibrated?

If even one fails → no launch. “ All systems should be green.”

Technical Meaning

Promise.all():

  • Resolves when all promises succeed

  • Rejects immediately if any promise fails

  • Returns results in input order

const fuel = Promise.resolve("Fuel loaded");
const weather = Promise.resolve("Weather clear");
const navigation = Promise.resolve("Navigation ready");

Promise.all([fuel, weather, navigation])
  .then(results => {
    console.log("All systems ready:", results);
    console.log("Launch successful!");
  })
  .catch(error => {
    console.log("Launch cancelled:", error);
  });

// Output:
// All systems ready: [ 'Fuel loaded', 'Weather clear', 'Navigation ready' ]
// Launch successful!

4 ) Promise.allSettled() — “Full Diagnostic Report”

Even if launch won’t happen, the Director wants a full report. “Give status of all systems!”

Technical Meaning

Promise.allSettled():

  • Waits for all promises to settle

  • Returns status of each

  • Never rejects

const fuelOK = Promise.resolve("Fuel loaded");
const weatherFail = Promise.reject("Heavy rainfall");
const navOK = Promise.resolve("Navigation ready");

Promise.allSettled([fuelOK, weatherFail, navOK])
  .then(results => {
    console.log("ISRO System Report:", results);
  });

// Output:
// [
//   { status: 'fulfilled', value: 'Fuel loaded' },
//   { status: 'rejected', reason: 'Heavy rainfall' },
//   { status: 'fulfilled', value: 'Navigation ready' }
// ]

5 ) Promise.any() — “At Least One Backup Works”

Among three communication systems, only one needs to work. “ If any of the systems works, then mission is safe!”

Technical Meaning

Promise.any():

  • Resolves on first success

  • Rejects only if all fail

  • Returns AggregateError if all reject

const primary = Promise.reject("Primary failed");
const secondary = Promise.reject("Secondary failed");
const backup = Promise.resolve("Backup relay active");

Promise.any([primary, secondary, backup])
  .then(result => {
    console.log("Communication established:", result);
  })
  .catch(error => {
    console.log("All systems failed:", error.errors);
  });

// Output:
// Communication established: Backup relay active

Unlike race(), this waits specifically for success.


6 ) Promise.race() — “First Response Wins”

Multiple heat sensors monitor re-entry. Among them, whichever sensor responds first determines action. “Whoever works first, that's final.”

Technical Meaning

Promise.race() settles as soon as the first promise settles.

const sensorA = new Promise(resolve =>
  setTimeout(() => resolve("Sensor A: Normal"), 3000)
);

const sensorB = new Promise(resolve =>
  setTimeout(() => resolve("Sensor B: Overheating"), 1000)
);

Promise.race([sensorA, sensorB])
  .then(result => {
    console.log("First sensor response:", result);
  });

// Output:
// First sensor response: Sensor B: Overheating

Timing decides everything here.


7 ) Promise.try() — “Test the Ignition”

Engineers test ignition script. It may throw an error instantly. “Chalo test karke dekhte hain.”

Technical Meaning

Promise.try() executes a function and wraps its result in a Promise.

function ignitionTest() {
  if (Math.random() > 0.5) {
    return "Ignition stable";
  } else {
    throw new Error("Ignition failure");
  }
}

Promise.try(ignitionTest)
  .then(result => console.log("Test Result:", result))
  .catch(error => console.log("Test Failed:", error.message));

// Possible Output:
// Test Result: Ignition stable
// OR
// Test Failed: Ignition failure

8 ) Promise.withResolvers() — “Final Decision by Chairman”

Now let's assume, when the mission is prepared, It depends on the manual final approval of the chairman of ISRO. (Though actually not in real life)

Technical Meaning

Promise.withResolvers() separates promise creation from resolution.

const { promise, resolve } = Promise.withResolvers();

promise.then(result => console.log("ISRO Decision:", result));

setTimeout(() => {
  resolve("Launch approved by Chairman");
}, 2000);

// Output (after 2 seconds):
// ISRO Decision: Launch approved by Chairman

Final Words

Asynchronous programming isn’t chaos. It’s structured coordination under uncertainty.

Exactly like ISRO managing:

  • Fuel

  • Weather

  • Communication

  • Sensors

  • Final approval

When you understand Promises this way, they stop feeling abstract.They start feeling practical(●'◡'●). And honestly — thoda interesting bhi!