← Back to release summary

Streams API: ReadableStream async iteration

Category
JavaScript
Type
Chromium catches up
Status
Enabled by default (Chrome 124)
Intent stage
None

Summary

The streams APIs provide ubiquitous, interoperable primitives for creating, composing, and consuming streams of data. This change adds support for the async iterable protocol to the ReadableStream API, enabling readable streams to be used as the source of for await...of loops.

Motivation

To consume a ReadableStream, developers currently acquire a reader and repeatedly call read(). By adding support for the async iterable protocol, web developers will be able to use the much simpler for await...of syntax to loop over all chunks of a ReadableStream. Web developers are already using polyfills to async-iterate over a ReadableStream. These polyfills usually work fine, but might not handle all edge cases correctly (such as when the stream errors during a read, or releasing the reader's lock when breaking out of a for await...of loop).

Standards & signals

Docs: https://github.com/whatwg/streams/blob/main/explainers/readable-stream-async-iteration.md

Samples: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream#async_iteration

View on chromestatus.com