跪拜 Guibai
← Back to the summary

async/await vs Promise: The Difference Is Error Flow, Not Syntax

async/await is not a replacement for Promise; it's syntactic sugar over Promise — async functions return a Promise themselves. The only real difference is that with await, errors go from "a value that must be passed along layer by layer" to "an ordinary piece of control flow." But the cost is that try/catch catches far less than most people think.

First, look at the kind of code you write every day:

// Callback style: nested layers
fetchUser(id, function (user) {
  fetchOrders(user.id, function (orders) {
    render(user, orders);
  });
});

Rewritten with async/await:

async function loadPage(id) {
  const user = await fetchUser(id);
  const orders = await fetchOrders(user.id);
  render(user, orders);
}

Reads like synchronous code, right? But it isn't. This piece explains how "looks synchronous" hides behavior that differs from synchronous code.

All conclusions in this article were tested on Node 22.22.2 / 24.22.3 / 26.13.1 + Chrome 152, and all four environments behaved identically.

1. First, Clarify: What async/await Actually Is

It's Syntactic Sugar, Not Something New

async function f() { return 1; }
console.log(f() instanceof Promise);   // true

An async function always returns a Promise. Even if you return an ordinary number, the caller receives Promise<number>.

So these two forms are completely equivalent underneath:

// Form 1
function f() { return Promise.resolve(1); }

// Form 2
async function f() { return 1; }

await works the same way — it's equivalent to "replace the .then callback with the code that follows":

const v = await somePromise;
// roughly equivalent to
const v = await somePromise.then(v => v);

These aren't "two technologies" — they're two ways of writing the same technology. So the question "should I use async/await or Promise" isn't exactly valid — you can mix both freely.

So When Should You Use Which?

In one sentence: for linear flows use async/await; for waiting on a bunch of things at once, use Promise combinators.

// Linear flow → async/await
const user = await getUser();
const orders = await getOrders(user.id);
const items = await getItems(orders);

// Wait on a bunch concurrently → Promise.all
const [user, config, feature] = await Promise.all([
  getUser(),
  getConfig(),
  getFeature(),
]);

The second form can also be written correctly as:

const user = await getUser();
const [config, feature] = await Promise.all([getConfig(), getFeature()]);

The difference isn't syntax, it's intent. Promise.all is a visible marker in the code that says "I explicitly want concurrency"; someone reading it instantly knows these requests fire simultaneously. With three consecutive awaits, whether they're concurrent or serial can't be told by reading the code — that's the only place where async/await genuinely invites misreading.

2. async/await's Real Advantage: Error Handling Becomes Control Flow

Callback style passes errors layer by layer

fetchUser(id, function (user) {
  fetchOrders(user.id, function (orders) {
    render(user, orders);
  }, function (err) {
    console.error(err);
  });
});

Promise.then is a bit better, but still requires passing the error as a "value" down:

getUser(id)
  .then(user => getOrders(user.id))
  .then(orders => render(orders))
  .catch(err => console.error(err));

With await:

try {
  const user = await getUser(id);
  const orders = await getOrders(user.id);
  render(orders);
} catch (err) {
  console.error(err);
}

These three pieces handle the same thing, but only the third has errors "flow along the code." The first two require you to guarantee every step remembers its error branch — miss one, and the error silently disappears.

Measured: what try/catch actually catches

This is the most worthwhile table in the article. Tested in all four environments, results identical:

Where the error occurs Does try/catch catch it?
await a rejected Promise Yes
Synchronous throw inside .then() callback Yes
Throw inside setTimeout in .then() callback No
Synchronous throw inside new Promise executor Yes
Throw inside setTimeout in new Promise executor No, and the Promise never settles

Note the difference between the last two rows — not "can't catch" but the Promise itself is broken:

new Promise((resolve) => {
  setTimeout(() => { throw new Error('boom'); }, 0);
  // executor already returned, resolve never called
});

This Promise stays pending forever; await on it hangs indefinitely. Measured in all four environments: pending-forever.

So "try/catch catches all async errors" is wrong. The accurate boundary is: try/catch can only catch errors thrown on the current synchronous execution chain. Once an error gets thrown inside a timer, an event callback, or another Promise's callback, try/catch can no longer reach it.

What about catch and finally?

try {
  const data = await load();
  return data;
} catch (err) {
  logger.error(err);
  throw err;              // to keep propagating up, you must rethrow
} finally {
  hideSpinner();
}

If catch doesn't throw, the error is swallowed — the outer layer receives a normal undefined. finally always runs, but it doesn't handle errors; it's just cleanup.

Also, rethrowing inside catch creates a brand-new error — the outer layer catches the new error, not the original (measured: inner K1 is replaced by outer-observed K2).

3. async/await's Real Cost: It Deceives Your Intuition

Pit 1: await is not "resume in place"

You might think await is "wait a bit, then continue exactly there." It isn't.

Measured execution order for this code:

console.log('1-sync start');
Promise.resolve().then(() => console.log('5-then(queued first)'));
(async () => {
  console.log('2-async entry');
  await null;
  console.log('6-after await');
})();
Promise.resolve().then(() => console.log('4-then(queued later)'));

Output:

1-sync start > 2-async entry > 5-then(queued first) > 6-after await > 4-then(queued later)

Look at rows 4 and 6 — 6-after await runs before 4-then(queued later), even though 4-then was queued earlier than the await.

Reason: await packages "the code after it" into a continuation and pushes it to the tail of the microtask queue. 4-then is queued after the async function body finishes, so it ends up after the continuation.

You rarely need this detail in daily work, but you must remember it for "execution order" matters — for example, if you want to insert logic into a microtask, await isn't "immediately," it's "in the next microtask round."

By the way, awaiting a non-Promise value (like await 42) also yields once — because the spec wraps it via Promise.resolve(42).

Pit 2: return and return await differ

// Form 1
async function f() {
  try {
    doSomething();
    return somePromise;      // does not wait
  } finally {
    cleanup();
  }
}

// Form 2
async function f() {
  try {
    doSomething();
    return await somePromise; // waits
  } finally {
    cleanup();
  }
}

Measured order for both:

Form Order
return somePromise a > c > b (finally runs first)
return await somePromise a > b > c (waits, then finally)

return does not wait for the Promise to settle, so finally cleanup may run before the Promise completes — if that Promise later uses a resource, that's a bug.

When must you write return await? When you need try/catch or finally to actually wait for the Promise to complete. Otherwise return await can be omitted, because an async function automatically awaits when it returns a Promise.

Pit 3: forEach with an async callback drops the Promise

This is mentioned in nearly every async article, but many people memorize it without understanding why.

[1, 2, 3].forEach(async (x) => {
  await doSomething(x);
  console.log(x);
});

Measured order:

Synchronous phase: start1, start2, start3
Final result: start1, start2, start3, end1, end2, end3

All three awaits start at the same time, and whoever finishes first prints first — the order is completely uncontrollable. And forEach returns undefined, so you can't get these Promises, therefore can't await them.

Root cause: forEach discards the callback's return value. Switching to map is the same, map gives you an array of Promises, but you still need to handle it yourself with Promise.all:

// Correct way
const results = await Promise.all(ids.map(async (id) => {
  const res = await fetch(`/api/user/${id}`);
  return res.json();
}));

For concurrency, use Promise.all + map, not forEach.

Pit 4: Serial await is three times slower

Measured three requests of 100ms each:

Form Time
Promise.all([a, b, c]) about 105ms
await a; await b; await c; about 320ms

That's a full three times difference. That's not an await problem, it's a problem with your code — consecutive awaits are inherently serial.

But don't blindly make everything concurrent: if request 2 depends on request 1's result, then you must be serial. The criterion is data dependency, not "which form is faster."

4. When to Use Promise, When async/await

Scenario Recommended form Reason
Linear flow with dependencies between steps async/await Natural error handling, code order equals execution order
Multiple independent operations Promise.all + map Concurrent and intent explicit
Only need the first successful Promise.any Can't be written with await
Only need the first settled (success or failure) Promise.race Same
Need all results but can't let a single failure abort Promise.allSettled Same
Old code / callback-style API refactor Wrap with new Promise When there's no async context
Library functions exposing a Promise Directly return Promise Avoids forcing callers to wrap an extra layer

A practical rule of thumb

If your function needs try/catch, use async/await; if you need to "wait for a bunch at once," use combinators. These two needs often appear together, and mixing them is the most common real-world form:

async function loadDashboard(userId) {
  // First serial: has dependencies
  const user = await getUser(userId);

  // Then concurrent: no dependencies
  const [orders, messages, prefs] = await Promise.all([
    getOrders(user.id),
    getMessages(user.id),
    getPrefs(user.id),
  ]);

  return { user, orders, messages, prefs };
}

5. Six Easily Tripped Pitfalls

1. try/catch can't catch errors inside timers

// Wrong: try/catch is completely useless
let err;
try {
  setTimeout(() => { throw new Error('boom'); }, 0);
} catch (e) {
  console.error(e);   // never runs
}

// Right: wrap the callback in a Promise
try {
  await new Promise((resolve, reject) => {
    setTimeout(() => {
      try { doSomething(); resolve(); }
      catch (e) { reject(e); }
    }, 0);
  });
} catch (e) {
  console.error(e);
}

2. Without rethrow in catch, the error vanishes

// Wrong: outer layer thinks it succeeded
try {
  await save();
} catch (err) {
  logger.error(err);
}

// Right
try {
  await save();
} catch (err) {
  logger.error(err);
  throw err;
}

3. One failure in Promise.all fails the whole set

// One failure, the whole array is unavailable
const [a, b, c] = await Promise.all([getA(), getB(), getC()]);

// Want "all, but allow individual failures"
const results = await Promise.allSettled([getA(), getB(), getC()]);
const ok = results.filter(r => r.status === 'fulfilled').map(r => r.value);

4. Promise.all doesn't cancel the losing requests

const p1 = fetch('/slow');
const p2 = fetch('/fast-but-fails');
await Promise.all([p1, p2]);   // p2 fails, this throws
// But p1 is still running! Nobody wants its result, and the request isn't cancelled

To truly cancel, use AbortController.

5. Promise.race also doesn't cancel the losers

race just means "the first to settle wins," the others still run to completion. To cancel, still AbortController.

Also Promise.race([]) never settles — with an empty array, no Promise triggers the race.

6. An async function without await is just an ordinary function

async function f() {
  doSomething();     // no await
  throw new Error('boom');
}

The Promise returned by f() will be rejected, but nobody catches it — it becomes an unhandled rejection. And doSomething() doesn't even wait.

The body of an async function runs synchronously from the start, and only yields at the first await.

6. A Quick Reference Table

[async function]
Return value      → always a Promise
Body              → runs synchronously from start, yields at first await

[await]
What it awaits    → any value (automatically wraps via Promise.resolve)
Where it yields   → tail of the microtask queue, not "in place"

[try/catch]
Can catch         → errors thrown on the current synchronous chain
Cannot catch      → errors inside timers / event callbacks / other Promise callbacks

[Combinators]
all               → succeeds only if all succeed, fails on first failure (losers still run)
allSettled        → ends only after all settle, never fails
any               → succeeds on first success, fails only if all fail
race              → ends on first settle (doesn't cancel losers; race([]) never settles)

[Three hard rules]
① forEach with async callback → Promise is dropped, use map + Promise.all
② Write out the intent for concurrency → Promise.all, don't expect readers to infer that consecutive awaits are concurrent
③ No rethrow in catch → error silently disappears

7. Version & Support

Environment async/await Notes
Node 22.22.2 Supported
Node 24.22.3 Supported
Node 26.13.1 Supported
Chrome 152 Supported

async/await is ES2017 syntax (async functions) / ES2018 feature (for await...of), and has long been a Baseline stable feature. If you're still debating whether to use it, you can safely start — the only exception is very old environments (IE11), and a project like that deserves a rewrite anyway.

Additional recommendations:

Appendix: Test Environment & Method

The two specific numbers referenced (105ms / 320ms) are measured on the same machine at the same moment, used to illustrate the ratio of "concurrent vs serial is three times slower" — the ratio is more meaningful than the absolute values.

Comments

Top 3 from juejin.cn, machine-translated. The original thread is authoritative.

庄里的老大爷

Learning this now is like joining the Nationalist army in 1949.

kanjiushi

Good summary. I always feel like I've read many JS/TS articles but still have many doubts and can't find satisfactory answers. So, I simply switched to Rust.

超级小韩

Learning this now feels too late already.