The independent file on technology, travel & lifeFrom Pakistan, for everywhere
Huzi Blogs.
The ArchiveSectionsSearch

Planning a trip? HTG Travels — flights, visas, hotels & Umrah, handled properly.

WhatsApp +92 317 5054959
Huzi Blogs.

An independent file on technology, travel and life — long-form guides written plainly, from Pakistan, for everywhere.

ShopMeet the Creator

Sections

  • Travel
  • Technology
  • Lifestyle
  • Programming
  • Sports
  • Linux
  • All sections

The Desk

  • The Archive
  • Search the file
  • Disclaimer & Data Privacy Policy
  • A project of huzi.pk

© 2026 blogs.huzi.pk — All rights reserved.

Set in Playfair Display & Inter

    HomeProgrammingStory
    Programming

    Beyond the Wait: Master Async/Await in JavaScript (2026)

    H

    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.

    Presented by

    HTG Travels — Plan the Trip, Skip the Runaround

    Flights, visas, Umrah packages and Hunza–Skardu tours, handled end to end from our licensed Sialkot desk. Real fares, hotel names in writing, and a human who answers — before you pay a rupee.

    Flights & rebooking Visa files Umrah 2026–27 Northern tours
    Visit huzi.pkWhatsApp +92 317 5054959

    Sialkot, Pakistan · Licensed agency · Fast quotes on WhatsApp


    You Might Also Like

    All-Over Print Embroidered Lawn Suit 3-Pc (2025) | 4-Side Embroidered Chiffon Dupatta

    All-Over Print Embroidered Lawn Suit 3-Pc (2025) | 4-Side Embroidered Chiffon Dupatta

    PKR 4900

    Heavy Embroidered Formal Chiffon Suit 2026 | Silk Gharara Trouser

    Heavy Embroidered Formal Chiffon Suit 2026 | Silk Gharara Trouser

    PKR 7770

    Luxury Heavy Embroidered Velvet Suit 2026 | Chiffon Dupatta & Plain Satin Silk Trouser

    Luxury Heavy Embroidered Velvet Suit 2026 | Chiffon Dupatta & Plain Satin Silk Trouser

    PKR 9650

    Luxurious Heavy Embroidered Net Bridal Maxi 2026 | Handwork Bodice & Net Dupatta

    Luxurious Heavy Embroidered Net Bridal Maxi 2026 | Handwork Bodice & Net Dupatta

    PKR 7750

    Luxurious Heavy Embroidered Velvet Suit 2026 | Emb. Silk Trouser & Chiffon Dupatta

    Luxurious Heavy Embroidered Velvet Suit 2026 | Emb. Silk Trouser & Chiffon Dupatta

    PKR 9600

    Keep reading

    Related files

    Programming
    English

    Python Async/Await Deep Dive 2026: The Complete Problem-Solving Guide

    asyncio.run, gather, TaskGroup, httpx sessions and the blocking-call escape hatch — the 2026 Python async patterns that actually ship, with copy-paste code.

    By HuziFile #536

    Read
    Programming
    English

    10 JavaScript Tricks That Will Save You Hours of Coding in 2026

    Ten patterns that pay rent: optional chaining, nullish coalescing, Object.groupBy, Set algebra, structuredClone, Array.fromAsync and the rest of the modern toolkit.

    By HuziFile #284

    Read
    Programming
    English

    The Modern Craftsman: Essential Guide to C++ (2026)

    What modern actually means now: std::print and structured bindings, smart pointers for ownership, ranges pipelines, concepts, and std::expected error handling in C++23.

    By HuziFile #89

    Read
    Programming
    English

    The Beginner's Guide to React: Building the Modern Web (2026)

    The component mental model, one-way props, the server/client split that defines modern React, and the scaffolding commands to start a real project today.

    By HuziFile #52

    Read
    Programming
    English

    Rust for JavaScript Developers 2026: The Complete Problem-Solving Guide

    Ownership, borrowing, Option, Result and the ? operator, Tokio and a first Axum API — Rust explained through the JavaScript habits you already have.

    By HuziFile #538

    Read
    Programming
    English

    The Connective Tissue: What is an API? (2026)

    APIs explained without the jargon: the restaurant analogy, REST versus GraphQL versus gRPC, webhooks, keys and OAuth, and the design habits that make an interface last.

    By HuziFile #462

    Read
    Back to the archive