async

const value = await new Promise((resolve) => {
  setTimeout(() => resolve("done"), 1);
});
console.log(value);

Output:

done

The loop

Node runs your synchronous code first Timers and I/O callbacks run when the stack clears A tight loop blocks everything, including timers

That is why a CPU heavy route stalls unrelated requests

await

await pauses that async function, not the whole thread Other work continues Treating await as a global pause causes most of the bad code in this area

setTimeout is not a sleep primitive

A timer guarantees a minimum delay, not an exact one A busy event loop makes it later Use timers for scheduling, not timing correctness

Parallel work

Start independent promises together, then await them Awaiting them one by one turns parallel work into sequential work That is a common and expensive mistake

Next

Failures in 09 errors

Posted