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

> 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.)

It seems to me we should be able to wrap the underlying source in a TeeSource that does this work.  The original stream just replaces its source with the new TeeSource and hands the TeeSource to the new stream.  The new stream then attaches itself to the TeeSource as well.  Any new tee() requests do the same thing (without creating a new TeeSource wrapper again, ideally.)

But I haven't read the spec recently enough to write this code.  So maybe I am missing something.

This would keep the mutation as non-observable to the immediate user of the original stream.

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

Received on Thursday, 19 March 2015 17:16:26 UTC