Beyond the Wait: Master Async/Await in JavaScript (2026)
By Huzi
File #119 · 3 min read
JavaScript runs one thing at a time, which makes waiting the language's central design problem. Fetching a profile, uploading a video, streaming tokens from a model — if the thread paused for any of it, the page would freeze. Async/await, nine years mature, is how modern JavaScript waits well.
The quick answer: Wrap every await in try/catch, run independent requests through Promise.all, and cancel anything long-running with AbortController. That trio covers most production async code — for...of, allSettled and for await handle the ordering, partial-failure and streaming edges.
From pyramids to await
Callbacks nested into pyramids, Promises flattened them into .then chains, and ES2017's async/await made asynchronous code read like synchronous code with try/catch intact. Top-level await now works in ES modules, so configuration and data loading happen before anything exports, no wrapper function needed. And Node ships a native global fetch — the old bootstrap ceremony is gone for good.
The shape of a modern fetch
One function, one try block, one honest error:
async function fetchUser() {
try {
const res = await fetch("https://api.example.com/user");
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return await res.json();
} catch (err) {
logger.error("fetch failed", { err });
throw err;
}
}
await pauses only the function, never the page — the event loop keeps serving clicks while the request is in flight. Catch by type when it matters: err instanceof ValidationError routes a form error back to the form and everything else to the log.
Parallel, not serial
The classic mistake is awaiting two independent requests one after the other and paying both latencies:
// slow: two round trips, paid in series
const user = await getUser();
const posts = await getPosts();
// fast: both in flight together
const results = await Promise.all([getUser(), getPosts()]);
For throttling huge batches, p-limit still leads. And when you need to resolve a promise from outside the executor, Promise.withResolvers is the clean modern shape instead of the old let-secret-variable dance.
Cancel what you start
An uncancelable request is a leak with extra steps. AbortController is the standard primitive, and fetch takes its signal directly:
const controller = new AbortController();
setTimeout(() => controller.abort(), 5000);
try {
const res = await fetch("/api/slow", { signal: controller.signal });
} catch (err) {
if (err.name === "AbortError") console.log("timed out");
}
In React, abort in the effect cleanup; on the server, abort when the user navigates away. For streaming, for await over response.body is exactly how the model SDKs deliver tokens as they arrive — chunks processed the moment they land.
| Tool | Use it when |
|---|---|
| try/catch around await | Every fetch — one function, one honest error |
| Promise.all | Independent requests — both latencies paid once |
| for...of with await | Order matters — forEach's callback ignores await |
| allSettled | Partial failure is acceptable |
| AbortController | Cancellation — fetch takes its signal directly |
| for await | Streaming response.body — chunks land as they arrive |
Pro tip: The forEach trap still bites — its callback ignores await, so a loop of saves fires without finishing. Use for...of when order matters, Promise.all with map when it does not.
Cancellation is a first-class concern in travel too — refund windows, date-change rules and waiver deadlines all expire. HTG Travel reads that fine print before you book, the way a careful engineer wires the abort signal before the fetch.
Families in Gaza have carried a deferred return for generations — a promise no people should be asked to hold pending this long; may theirs resolve, with justice. Sudan's displaced hold promises of return across borders and years — may theirs resolve soon.
Half of travel misery is serial waiting — token numbers, embassy queues, forms that spawn forms. At HTG Travel we parallelize it: passport renewals, visa files and attestation runs proceed while you get on with life, and one message gets a status. Bring the stack; we return a date — +92 317 5054959.




