Intent to Prototype and Ship: Streams API: ReadableStream async iteration

422 views
Skip to first unread message

Mattias Buelens

unread,
Feb 21, 2024, 10:58:02 AMFeb 21
to blink-dev
Contact emails

mattias...@gmail.com


Explainer

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


Specification

https://streams.spec.whatwg.org/#rs-asynciterator


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.



Blink component

Blink>Network>StreamsAPI


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).



Initial public proposal

None


Search tags

streams


TAG review

None


TAG review status

Not applicable. (This is a small feature with a mature specification that's already shipping in Firefox.)


Risks

Interoperability and Compatibility

Low risk. The Streams API has already been standardised for a long time. Async iteration is already supported in one other browser (Firefox) and several JavaScript runtimes (Node.js, Deno, bun).



Gecko: Shipped/Shipping (https://bugzilla.mozilla.org/show_bug.cgi?id=1525852) Shipped in Firefox 110


WebKit: No signal (https://github.com/WebKit/standards-positions/issues/319)


Web developers: Positive (https://github.com/whatwg/streams/issues/778) Developers already expect this to work, and often use a polyfill.


Other signals:


Activation

Async iteration can be feature detected by checking the existence of `ReadableStream.prototype.values`. Various polyfills already exist in the wild. (e.g. https://jakearchibald.com/2017/async-iterators-and-generators/)



WebView application risks

Does this intent deprecate or change behavior of existing APIs, such that it has potentially high risk for Android WebView-based applications?

None



Debuggability

No special support needed. The JavaScript debugger is already sufficiently capable of handling for await...of loops.



Is this feature fully tested by web-platform-tests?

Yes

https://wpt.fyi/results/streams/readable-streams/async-iterator.any.html



Flag name on chrome://flags

None


Finch feature name

ReadableStreamAsyncIterable


Requires code in //chrome?

False


Tracking bug

https://issues.chromium.org/issues/40612900


Estimated milestones

No milestones specified



Link to entry on the Chrome Platform Status

https://chromestatus.com/feature/5143121161879552


This intent message was generated by Chrome Platform Status.


Yoav Weiss (@Shopify)

unread,
Feb 21, 2024, 11:03:52 AMFeb 21
to Mattias Buelens, blink-dev
LGTM1

Thanks for catching us up here!!

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/b1438dfd-ec71-4e18-b34d-0213aff6250cn%40chromium.org.

Chris Harrelson

unread,
Feb 21, 2024, 12:09:55 PMFeb 21
to Yoav Weiss (@Shopify), Mattias Buelens, blink-dev
Hi,

Please start the reviews for the 5 other areas shown below in your chromestatus entry (once you've done show they should turn blue, not gray):

Screenshot 2024-02-21 9.08.57 AM.png


Chris Harrelson

unread,
Feb 21, 2024, 2:07:26 PMFeb 21
to Mattias Buelens, blink-dev, yoav...@chromium.org
Thanks!

LGTM2

On Wed, Feb 21, 2024 at 11:03 AM Mattias Buelens <mattias...@gmail.com> wrote:
Thanks Chris, they're all blue now.

Op woensdag 21 februari 2024 om 18:09:55 UTC+1 schreef chri...@google.com:

Mattias Buelens

unread,
Feb 21, 2024, 2:17:11 PMFeb 21
to blink-dev, chri...@google.com, Mattias Buelens, blink-dev, yoav...@chromium.org
Thanks Chris, they're all blue now.

Op woensdag 21 februari 2024 om 18:09:55 UTC+1 schreef chri...@google.com:
Hi,

Domenic Denicola

unread,
Feb 21, 2024, 11:58:18 PMFeb 21
to Chris Harrelson, Mattias Buelens, blink-dev, yoav...@chromium.org
Reply all
Reply to author
Forward
0 new messages