async/await exactly · senior
Async iterators, async generators and for await
An async iterator's next() returns a promise of { value, done }, async function* produces one, and for await...of consumes it one item at a time — the natural tool for paginated APIs, streams and sequences of events.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Protocol: objSymbol.asyncIterator returns an object whose next() returns Promise<{ value, done }>.
- async function* can both await and yield. The consumer pulls, so the next page is fetched only when it is needed.
- for await...of also works on a sync iterable of promises, awaiting each in order.
- break inside for await calls the iterator's return(), so a finally block in the generator runs: close connections or abort requests there.
- Array.fromAsync(asyncIterable) collects everything into an array (ES2024, Baseline widely available).
- A ReadableStream is async-iterable in Node and modern browsers: for await (const chunk of response.body).
- Atlassian's Karat screen asked about async generators, yield, await and for await from memory (2025).
The red pen
Common traps: mistake → fix
Mistake: for await runs iterations in parallel
Fix: strictly one at a time.
Mistake: An async generator fetches everything up front
Fix: it is lazy and fetches on demand.
Easy to hard
Questions interviewers ask, easy to hard
- What is an async generator?
- Paginate an API with an async generator and for await.
- What happens when you break out of for await?
- How do you read a streaming fetch response, and what is back-pressure?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.