Re: [streams] First draft at tee algorithms, for critique (#302)

To keep the original stream available and its state unchanged even after teeing, we need to add one more layer in addition to the stream and the reader. Introduction of the new layer doesn't necessarily require definition of a new class but we need to at least clearly define a concept to explain the new layer.

Like `Blob`'s `slice()` creating a new reference to the same underlying bytes, `readableStream.tee()` internally creates a cloner like Domenic's code. `readableStream` detaches its underlying source and connects the source with the cloner and creates a new stream, and attach itself and the new stream to the read end of the cloner. Here, the "underlying source" is a new boundary. The underlying source must not hold the resolving function / rejecting function of the promise returned to the consumer since once the detaching happens and the cloner is inserted, the cloner must do cloning and the cloner should call the resolving function / rejection function. As far as we define this thin-wrapper style stream class in good form, I think it's not going to be so terrible. But I'd rather want to try to keep the number of layers small.

----

For `Response` without a stream, it's simple and natural to add a method named clone() directly onto it which doesn't affect itself but creates a new cloned instance.

But once there's a stream on it, the stream doesn't fit this approach well. It's unfortunate but we shouldn't be dragged by the fact to introduce unnecessary complexity.

---
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/pull/302#issuecomment-83359897

Received on Thursday, 19 March 2015 06:28:38 UTC