A promise represents an asynchronous result, but its observable behavior depends on more than the promise object itself. ECMAScript defines promises, while the JavaScript engine and host runtime influence scheduling and event ordering. section 1.3.3 section 8.0
A promise resolution schedules reactions through the microtask queue. Those reactions can run after a callback returns but before later task processing, creating timing bugs when promise-based work is mixed with host events. Runtime-specific rules also affect when rejected promises are classified as unhandled. section 8.5.4 section 10.4.5
Stream completion before async processing
An asynchronous data callback may still be waiting in the microtask queue when a stream emits its end event, so results.length can be zero or incomplete. Track pending promises and await Promise.all, or consume the stream with for await...of before collecting results. section 8.5.4
Promise allocation at scale
Web Streams create promises for reading, writing, and backpressure. In CPU-bound pipelines, repeated allocations, retained results, and microtask processing can dominate performance; in I/O-bound pipelines, the cost may be less visible. section 10.4.5
for await (const chunk of readable) {
pending.push(transform(chunk));
}
// We don’t care what order the transforms complete
const results = await Promise.all(pending);
console.log(`Processed ${results.length} chunks`);
Use the async-iterable example to compare explicit stream events with promise collection and Promise.all. section 8.5.4










