Re: [whatwg/streams] Add a realtime mode to ReadableStream.tee (Issue #1186)

> > * Treat this as a new pull ... (If branch 1 manages to catch up in the meantime and also starts pulling, we'll also enqueue it to branch 1.)
> 
> Is "in the meantime" = anytime before a chunk newer than "new pull" is delivered to branch 2? (The pull promise is [unreliable](https://alvestrand.github.io/mediacapture-transform/#processorpull) here imho)

Yes, that's what I meant.

> If the underlying source's internal queue is not empty, this would seem to devolve into delivering different chunks to each branch, pulling at a rate faster than either of the branches would have individually. I don't think we ever want to steal chunks from the fast branch, even if upstream has backed up.

Agreed. We also definitely don't want to pull *faster* than the fastest branch, because that could get very bad if you do *multiple* `tee()`s in a "chain".

I probably should have thought a bit more about this option first, because now it sounds like an *obviously* bad idea. 😛

> > * Store the previous chunk, and enqueue it when branch 2 (eventually) starts pulling. This chunk can be overwritten when branch 1 pulls in more chunks in the meantime.
> 
> This would appear to keep the pull rate = max(pull rate A, pull rate B), and expose mostly the same (cloned) frames, which seems desirable or at least easier to reason about.

Yes, this seems much better. 👍

> > This would imply that if `structuredClone` is true, we always need to clone the chunk. Which is a problem if explicit closure is needed.
> 
> Yes, though we need to solve that somehow anyway for when a stream is errored.

Yes, whatever solution we end up choosing for #1185 will also need to be integrated in `tee()`. We need to close the cloned chunk when it gets replaced by a newer one, or when the branch that *would* have received the clone gets cancelled.

We do have to be careful with how we design explicit closure. If we go with `[Transferable, Closeable]` as in https://github.com/whatwg/streams/issues/1187#issuecomment-972733678, it should be fine: we can use the same "close a chunk" algorithm inside `ReadableStreamTee`. If we go with something like `UnderlyingSink.closeChunk(chunk)`, then we have to *copy* that algorithm over to the two branches. (Otherwise, we might run into problems if the original stream clears its algorithms before both branches are done.)

-- 
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/1186#issuecomment-976006778

Received on Monday, 22 November 2021 23:32:36 UTC