- From: Domenic Denicola <notifications@github.com>
- Date: Tue, 13 Jan 2015 16:00:26 -0800
- To: whatwg/streams <streams@noreply.github.com>
- Message-ID: <whatwg/streams/issues/258/69846255@github.com>
OK. I thought about this for about an hour. I don't think there's a fix possible given the current design. Our requirements are contradictory: - `rs.ready` needs to fulfill when the stream transitions away from `"waiting"`, - AND it must not fulfill when there is a reader present, - EXCEPT if the promise was originally retrieved by the reader itself as part of [the reader's `ready` getter](https://github.com/whatwg/streams/blob/25a514128c35f362f0978576eeac006e90107af8/reference-implementation/lib/exclusive-stream-reader.js#L27-L32). There's no real workaround here, without somehow telling the stream "I am the reader, give me a special `ready`." One design that comes to mind is then to pass in a `getReady` function to the ExclusiveStreamReader constructor. (I think this was @yutakahirano's original design.) We might as well expand this to `getState` and `read` functions, which helps avoid the try/finally lock/unlock stuff for those. Alternately, we are already coupling to the presence of the [[reader]] slot. We could just couple to the presence of the [[readyPromise]] and [[state]] slots. (And just abstract ReadFromReadableStream into an abstract op that we call directly.) Subclasses of ReadableStream inherit those too, so things will work. Except... This latter design means that if you override `read()`/`state`/`ready` in your subclass, those will *not* be called by the reader. But, the more I think about this (that is why I took an hour), the more I am OK with that. Overriding those is very brittle. The only legitimate overrides I can imagine are "instrumentation"-like ones, that observe the data passing through. (E.g., overriding `read()` to fire a `"data"` event on the stream every time it is read, somewhat like in Node.js streams.) And for those, it's actually preferred that the exclusive reader not trigger the instrumentation hooks---non-observability is kind of the whole point! So, I'm going to try ripping stuff out and more tightly coupling ExclusiveStreamReader to ReadableStream (and ReadableByteStream, and anything else that implements those specific slots). --- Reply to this email directly or view it on GitHub: https://github.com/whatwg/streams/issues/258#issuecomment-69846255
Received on Wednesday, 14 January 2015 00:00:53 UTC