← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

async/await

javascript ES2017 Intermediate
debt(d7/e3/b3/t7)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). ESLint can catch some patterns (e.g., no-floating-promises with TypeScript plugin, no-await-in-loop), but many misuses — like missing try/catch, async in forEach, or not awaiting a promise — require careful review or manifest only at runtime as silent failures or crashes. The tools listed (eslint, typescript) help but don't catch all cases automatically without specific rule configuration.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix indicates wrapping in try/catch, swapping sequential awaits for Promise.all(), and adding unhandledRejection handlers — these are small, targeted fixes within one function or component, not one-liners but not cross-cutting refactors either.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3). async/await applies to web and cli contexts broadly, but individual misuses are typically localised to specific functions or modules. The pattern doesn't impose a systemic architectural burden on the whole codebase — fixing one async function rarely forces changes across the system.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7). The misconception field explicitly states that developers believe async/await makes JavaScript 'truly synchronous' — a fundamental misunderstanding about event loop behavior. Common mistakes like async in forEach, missing awaits, and sequential vs. parallel execution all stem from this wrong mental model, which contradicts how similar synchronous constructs behave in other languages.

About DEBT scoring →

Also Known As

async await JS async functions await keyword

TL;DR

Syntactic sugar over Promises — async functions always return a Promise; await pauses execution until the awaited Promise settles.

Explanation

async/await (ES2017) makes asynchronous code read like synchronous code. An async function implicitly returns a Promise — returning a value resolves it, throwing rejects it. await can only appear inside an async function and pauses its execution until the awaited Promise settles, without blocking the event loop. Error handling uses try/catch identically to synchronous code. Common pitfalls: awaiting in a loop sequentially (use Promise.all() for parallel execution), forgetting await (function returns a Promise, not the value), and unhandled promise rejections. Top-level await is available in ES modules. In PHP, the conceptual equivalent is Fiber suspension in Revolt/Amp.

Diagram

sequenceDiagram
    participant CALL as Caller
    participant ASYNC as async function
    participant IO as I/O (fetch, DB)
    CALL->>ASYNC: call fetchUser(id)
    ASYNC->>IO: await fetch('/api/user')
    Note over ASYNC,IO: Fiber suspended - main thread free
    IO-->>ASYNC: response
    ASYNC->>IO: await response.json()
    IO-->>ASYNC: user data
    ASYNC-->>CALL: return user
    Note over CALL,IO: await unwraps Promise<br/>try/catch handles rejection

Common Misconception

async/await makes JavaScript truly synchronous. async/await is syntactic sugar over Promises — it makes asynchronous code read synchronously but does not block the event loop. An awaited operation suspends the current async function, allowing other callbacks to run.

Why It Matters

async/await makes asynchronous code readable as sequential statements — replacing .then() chains with code that handles errors with try/catch like synchronous code.

Common Mistakes

  • Not awaiting a Promise — the function continues before the async operation completes.
  • Sequential awaits when operations are independent — use Promise.all() for parallel execution.
  • Not wrapping await in try/catch — unhandled rejections crash Node.js processes.
  • async functions in array methods like forEach — forEach doesn't await the callbacks.

Code Examples

✗ Vulnerable
// Sequential awaits — takes 3 seconds when 1 would suffice:
async function loadDashboard() {
    const user    = await fetchUser();    // 1s
    const orders  = await fetchOrders();  // 1s — could run in parallel!
    const stats   = await fetchStats();   // 1s — could run in parallel!
}

// Parallel:
const [user, orders, stats] = await Promise.all([fetchUser(), fetchOrders(), fetchStats()]);
✓ Fixed
// Sequential (slow) vs parallel (fast)
const [a, b] = await Promise.all([fetchA(), fetchB()]);

// Error handling
try {
  const data = await fetch('/api').then(r => r.json());
} catch (err) {
  console.error('Failed:', err);
}

Added 15 Mar 2026
Edited 22 Mar 2026
Views 40
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 1 ping W 0 pings T 0 pings F 2 pings S 0 pings S 0 pings M 0 pings T 1 ping W 1 ping T 1 ping F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 2 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F
No pings yet today
No pings yesterday
Perplexity 9 Amazonbot 8 ChatGPT 3 Unknown AI 3 SEMrush 3 Google 2 Ahrefs 2 Majestic 1
crawler 30 pre-tracking 1
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Low
⚡ Quick Fix
Always await inside try/catch; use Promise.all() for parallel operations not sequential awaits; add a global unhandledRejection handler
📦 Applies To
javascript ES2017 web cli
🔗 Prerequisites
🔍 Detection Hints
Sequential awaits in a loop that could be Promise.all(); unhandled promise rejection; missing try/catch around await
Auto-detectable: ✓ Yes eslint typescript
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Medium ✗ Manual fix Fix: Medium Context: Function Tests: Update

✓ schema.org compliant