Re: [whatwg/streams] ReadableStreamClose with async iterator and pending read requests errors (#1100)

Interesting! The reference implementation fails my new test. 😛

In the current version, we first call the close/error steps of all read requests, and afterwards we resolve/reject the reader's closed promise. When the close/error steps of a read request release the reader's lock, the stream's state is already `'closed'` so [we use `promiseRejectedWith`](https://github.com/whatwg/streams/blob/ca74e0ed1aa9dc70ce87e546c5f08c1fa6d96fcb/reference-implementation/lib/abstract-ops/readable-streams.js#L604) to replace the closed promise (which is actually still pending!) with a newly rejected promise. However, when we later on try to [resolve the closed promise in `ReadableStreamClose`](https://github.com/whatwg/streams/blob/ca74e0ed1aa9dc70ce87e546c5f08c1fa6d96fcb/reference-implementation/lib/abstract-ops/readable-streams.js#L473), it throws on [this line](https://github.com/whatwg/streams/blob/ca74e0ed1aa9dc70ce87e546c5f08c1fa6d96fcb/reference-implementation/lib/helpers/webidl.js#L26) because there is no `resolve` method in the entry of our promise side table! 😱 This happens because `promiseRejectedWith` creates an entry with [only the `stateIsPending` property](https://github.com/whatwg/streams/blob/ca74e0ed1aa9dc70ce87e546c5f08c1fa6d96fcb/reference-implementation/lib/helpers/webidl.js#L47), no `resolve` or `reject` properties.

In short: `resolvePromise(promiseRejectedWith(reason), value)` throws in the reference implementation. This is just a silly bug in our reference implementation though, browsers that properly implement the WebIDL promise helpers shouldn't have this problem. Still, I'll fix our reference implementation to return immediately if `stateIsPending` is already `false`, before trying to call `resolve` or `reject`. 😉

-- 
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/1100#issuecomment-762509869

Received on Monday, 18 January 2021 23:18:09 UTC