3 ms·
Hey there, I'm both the author of the browser streams spec [1] and the current champion of the async iteration spec [2] that this article discusses. We have, in
by domenicd 10y ago
Hey there, I'm both the author of the browser streams spec [1] and the current champion of the async iteration spec [2] that this article discusses. We have, in fact, thought through the interaction here :).
johnsonjo got things basically right in his response. We go into more detail in the streams FAQ, including the connection to observables:
- "How do readable streams relate to observables or EventTarget?" [3]
- "How do readable streams relate to async iterables?" [4]
The basic punchlines are:
> Observables and readable streams both share the semantic of "zero or more chunks, followed by either an error or done signal". But beyond that, they are not very comparable.
and
> The best analogy is something like "readable streams is to async iterable as array is to sync iterable." That is, just like arrays are a specialized type of iterable optimized for memory locality and random access, readable streams are a specialized type of async iterable optimized for things like off-main-thread data transfer and precise backpressure signaling.
I do indeed expect us to start speccing the [Symbol.asyncIterator]() for readable streams, and shipping it (behind a flag at first) in Chrome, within the next month or so.
[1]: http://streams.spec.whatwg.org/ http://streams.spec.whatwg.org/
[2]: https://tc39.github.io/proposal-async-iteration/ https://tc39.github.io/proposal-async-iteration/
[3]: https://github.com/whatwg/streams/blob/master/FAQ.md#how-do-readable-streams-relate-to-observables-or-eventtarget https://github.com/whatwg/streams/blob/master/FAQ.md#how-do-...
[4]: https://github.com/whatwg/streams/blob/master/FAQ.md#how-do-readable-streams-related-to-async-iterables https://github.com/whatwg/streams/blob/master/FAQ.md#how-do-...