TechSkills of Future

10-Minute Async Learning Streak Progress with Consistent

10-Minute Asynchronous JS Programming Power Streak

10-Minute Asynchronous JS Programming Power Streak

Maintain a learning habit in just 10 minutes Prog with these easy methods.

01. The Event Loop

02:00

Understand how JavaScript handles background tasks using the Callback Queue. It doesn’t stop the program; it schedules for later.

console.log("Start");
setTimeout(() => console.log("Timer Finished"), 1000);
console.log("End"); 
// Output: Start, End, Timer Finished
I understand Non-Blocking execution Behind The Scenes

02. The Promise Lifecycle

IMPORTANT
01:30

A Promise is always in one of three states. Understanding this helps debug “hanging” code.

  • Pending: Initial state, neither fulfilled nor rejected.
  • Fulfilled: Operation completed successfully.
  • Rejected: Operation failed.
const myPromise = new Promise((resolve, reject) => {
  const success = true;
  if (success) resolve("Data received!"); // Transitions to Fulfilled
  else reject("Error occurred!"); // Transitions to Rejected
});
I understand the 3 states of a Promise.

03. Async/Await & Errors

01:30

Writing asynchronous code that reads like synchronous JS learning habit code, coupled with robust try/catch blocks for safety.

async function fetchData() {
  try {
    const res = await fetch('https://api.example.com/data');
    if (!res.ok) throw new Error("Network issue");
    return await res.json();
  } catch (err) {
    console.error("Caught:", err.message);
  }
}
I can use Async/Await and handle errors.

04. Parallel Concurrency

01:30

Don’t await sequentially if tasks are independent. Use Promise.all to fire them all at once.

// Executes simultaneously
const [user, settings] = await Promise.all([
  fetchUser(id),
  fetchSettings(id)
]);
I can perform parallel data fetching.

05. Graceful Handling

ADDITIONAL
01:00

Unlike Promise.all (which fails if one fails), Promise.allSettled waits for everything to finish, regardless of success or failure.

const results = await Promise.allSettled([fetch(p1), fetch(p2)]);
results.forEach(result => {
  if (result.status === 'fulfilled') console.log("Value:", result.value);
  if (result.status === 'rejected') console.log("Reason:", result.reason);
});
I can handle mixed success/failure results.

06. The Race Pattern

01:00

Use Promise.race to implement timeouts. Useful when you need a result fast or a fallback if the server hangs.

const timeout = new Promise((_, rej) => 
  setTimeout(() => rej("Too slow!"), 5000)
);

// Whichever finishes first wins
await Promise.race([fetchData(), timeout]);
I understand the Race pattern.

07. Success Search (Promise.any)

CONCEPTUAL
01:00

Important distinction: Promise.any waits for the first success. If one fails, it keeps waiting for others. Promise.race stops as soon as anything happens.

// Useful for mirror servers: get the fastest successful response
try {
  const firstSuccessfulResult = await Promise.any([
    fetchFromServerA(),
    fetchFromServerB()
  ]);
} catch (err) {
  console.log("All servers failed");
}
I know when to use Promise.any vs Promise.race.

08. Clean Cleanup

ADVANCED
01:00

How to stop a network request that is no longer needed (e.g., user navigated away). Use AbortController.

const controller = new AbortController();
fetch('/api/large-data', { signal: controller.signal });

// Later, to cancel:
controller.abort(); 
I can cancel requests with AbortController.

09. Async Iteration

EXPERT
01:00

When dealing with streams or paginated data, use for await...of to loop through async values as they arrive.

async function* generateStream() {
  yield "Data Chunk 1";
  await new Promise(r => setTimeout(r, 1000));
  yield "Data Chunk 2";
}

for await (const chunk of generateStream()) {
  console.log(chunk); // Logs as they arrive
}
I can use Async Generators and for-await loops.

10. Microtask Priority

00:30

Expert tip: Promises (Microtasks) always execute before Timers (Macrotasks). This determines the “True” order of operations.

setTimeout(() => console.log("Macrotask"), 0);
Promise.resolve().then(() => console.log("Microtask"));

// Result: "Microtask" prints first!
I understand Task vs Microtask priority.

Air conditioners (AC): power, price, Cooling, & lifespan.

Leave a Comment

Your email address will not be published. Required fields are marked *