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

> Ok, this is where I had different expectations. I was thinking branch1 === originalStream, but here you are effectively consuming it.
>
> Is it consumed because of the way this is written as an external function right now? It seems like particular stream implementations could be smart enough to copy their internal details to produce a new branch.

Sort of. It's consumed because it's meant to be general functionality that can work with any stream. It's true that if you created a stream implementation with a focus around being clone-able, you could make it work without consumption. For example, you could create a stream implementation that keeps track of all clones that have been produced, and every time a chunk is enqueued into the stream by the underlying source, it also enqueues it into the clones. (Or for byte streams, each read---from either the original stream or the clone---also copies the data into an internal buffer. You then ref-count which memory regions have been consumed by which subset of [original stream, ...clones], and only release a region when all clones have consumed it.)

This seems a lot more complex though. In particular we either have certain streams being complex and cloneable and other not, or we add complexity to all streams to track their clonability. Compared to just a simple operation that can work with any stream through its preexisting interface, I'm not sure it gives much. What is the advantage?


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

Received on Thursday, 19 March 2015 06:24:48 UTC