Intermediate~6h

JavaScript: Async

The half that is about time

Everything else in a program happens where you put it. This does not: a line runs when a queue gets to it, and the queue has rules. Learn them until the order is obvious, then build what uses them — a runner that bounds every call, limits how many run at once, and stops the moment it is told to.

Modules
6
Drills
11
Build steps
5
Time
~6h

Walk out able to

Predict the exact print order of any mix of sync code, promise reactions and timers — and cancel work that is no longer wanted.

What you work through

01

Callbacks and promises

The contract nothing enforced, and what replaced it.

02

await, and what it cost

Suspension, concurrency, and the latency you stopped paying.

03

Sync, microtask, macrotask

The checkpoint rule, drilled until the order is obvious.

04

Failure and cancellation

Rejections that stay caught, and work that actually stops.

The pitch

What you practise, and what you leave with

A dependency-free job runner over a deterministic offline service: bounded, limited, retried, and provably stopped when it is told to stop.

You will practise

  • Callback contracts, chains and async syntax
  • Combinators, and what they do not cancel
  • Sync, microtask and timer ordering
  • Rejections, retries and abort signals

Afterwards you can

  • Order a mixed program first time
  • Cost a waterfall before writing it
  • Keep every rejection attached to a handler
  • Cancel in-flight work and prove it

Modules

6 modules, 31 items

Lessons explain one idea. Drills repeat it until it sticks. Build steps make something that exists afterwards.

  1. 1

    What a callback costs

    ~48 min

    Name the guarantee a callback API is breaking, and hold the result yourself instead.

    • LessonWhy time is the hard half6 min
    • LessonWhat you gave away with the callback7 min
    • LessonHold the result yourself7 min
    • DrillName the guarantee it broke12 min
    • Build stepWrap a callback API in a promise16 min
  2. 2

    A value that has not arrived

    ~45 min

    Say what a chain ends with, and pick the combinator a requirement actually names.

    • LessonWhat a link hands to the next7 min
    • LessonThe one-word bug in a chain6 min
    • LessonA catch resumes the chain6 min
    • DrillSay what the chain ends with13 min
    • DrillPick the combinator13 min
  3. 3

    Write it as if it were sync

    ~1h

    Read an async function as a suspension, and stop paying double for independent calls.

    • LessonAn async function is a suspension7 min
    • LessonA waterfall nobody asked for7 min
    • LessonConcurrent is not parallel6 min
    • DrillCost the awaits12 min
    • DrillGet the syntax into your fingers14 min
    • Build stepUnpick a request waterfall16 min
  4. 4

    Sync, microtask, macrotask

    ~44 min

    Predict the print order of any mix of synchronous code, reactions and timers.

    • LessonOne loop, two queues8 min
    • LessonThe checkpoint drains to empty8 min
    • DrillPut the output in order14 min
    • Build stepWatch one pass of the loop14 min
  5. 5

    Errors that cross an await

    ~51 min

    Keep a rejection attached to a handler, wherever the await boundary put it.

    • LessonWhere a rejection actually lands7 min
    • LessonThe three ways it goes quiet8 min
    • DrillSay which handler catches it12 min
    • DrillSay what to do with the status12 min
    • DrillDecide whether to send it again12 min
  6. 6

    Stop work you no longer want

    ~1h

    Bound every call, cancel what is superseded, and know what abort does not stop.

    • LessonWhat abort actually stops7 min
    • LessonIt stops only what is watching8 min
    • DrillSay what happens after abort12 min
    • DrillCost a retry policy12 min
    • Build stepBuild a runner that survives a bad day26 min
    • Build stepProve it stops when told22 min

Nothing here runs when you wrote it.

The first item is free. ~6h of focused work, at your own pace.

Intermediate~6h6 modules