Re: [whatwg/streams] Readable byte stream must call pull after receiving new chunk (#877)

Maybe some background information, in case you're wondering how I ended up here...

I'm currently working on an adapter library between native streams (e.g. from a fetch `Response.body`) and polyfilled streams. Since many browsers are not yet up-to-date with the latest version of the spec, some features (e.g. `pipeTo` in Edge or readable byte streams in Chrome) are not yet available in these native streams. As such, users are in an awkward position when they want to use the latest features from a polyfill implementation together with streams created by the browser.

My idea is to implement helper functions that create an underlying source/sink that pulls from/writes to a given (native) readable/writable stream. This way, the created source/sink can be passed to a polyfilled stream constructor, resulting in a polyfilled stream that pulls from/writes to a native stream. Under the hood, the created source/sink implementations request a reader/writer from the original stream and use that to respond to `pull`/`write` calls.

To verify my adapter for readable streams, I create my own `ReadableStream` class whose constructor does the following:
1. Construct a (native or polyfilled) `ReadableStream` using the passed underlying source.
2. Construct an adapting source that wraps that stream (using my adapter).
3. Construct a polyfilled `ReadableStream` using the adapting source.

So you end up with something like:
```
polyfill stream -> adapter source -> native stream -> original source
```
And then I try to get this `ReadableStream` implementation to pass all Web platform tests for streams! 😆 Incredibly, many tests are already passing, but I got stumped by this one test called _"ReadableStream with byte source: Respond to pull() by enqueue() asynchronously"_. From my investigation, it's not my adapting source that's causing the test to fail, but a bug in the reference implementation and in the spec itself.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/877#issuecomment-363606785

Received on Tuesday, 6 February 2018 23:54:04 UTC