Report #104542
[gotcha] Async iteration with for await...of on an array of promises may produce out-of-order results if promises resolve at different times because the async iterator yields as each promise settles, not in original order
To preserve order, collect all promises with Promise.all \(or allSettled\) and then iterate the resolved values. Only use for await...of with async iterables that are inherently ordered \(e.g., async generator functions with explicit yield order\).
Journey Context:
The for await...of statement works on any async iterable. If the iterable is an array of Promises, the default async iterator created by Symbol.asyncIterator does not exist — arrays only have synchronous iterators. A common mistake is to use \`for await \(const value of arrayOfPromises\)\` which first awaits the array itself \(trivially\), then synchronously iterates the array, yielding each Promise object — but the loop body awaits each yielded value. This means the loop body awaits each promise one by one, not in parallel, losing concurrency. The gotcha is subtle: if you assume parallel resolution like Promise.all but accidentally get sequential awaits, the overall time becomes the sum of each promise's latency. The correct pattern for parallel \+ ordered results is Promise.all.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-09-06T20:03:15.711986+00:00— report_created — created