Re: [whatwg/streams] Make the internal queue observable (#1167)

I understand your point from the implementation perspective, however I did stress explicitly that the ability to peek at the queue is at any rate made "uninvasive" in the sense that the queue is not disturbed, merely observed. Furthermore, since the queue *is* exposed to at least the constructor of the stream -- through the initialization object being passed a controller with the `desiredSize` property, it can still be made observable only to the stream constructor (whether through the subclass calling super constructor or the caller calling `new ReadableStream(...)`.

It doesn't have to leak to arbitrary stream user context -- only being available on the controller object, but in contrast to `desiredSize` (which _is_ already controller making the queue size available) there will be a away to notify of changes.

Performance is obviously important, but if the caller wants to observe the queue, can it be made so that the penalty is only paid for that particular stream, when observation is enabled? One could utilize the `....Observer` pattern -- employed with `MutationObserver`, `ResizeObserver`, `IntersectionObserver` etc. An argument can be made the pattern is employed precisely to otherwise not perturb default behaviour of respectively, document nodes, element dimensions, and inter-element layout interactions etc. In the same way, attaching an observer to a stream via `observer.observe(stream)` (and, conversely, `unobserve`) could be implemented in a way where only observed streams bear the cost?

Like I said, the queue _is_ a finite and _variable-sized_ resource, much like the rest of the scripting context (e.g. a Web page), so since `desiredSize` is already exposed anyway, why not expose ability to observe _change_ to said size? Meaning, the queue can already be peeked at (if you can access the controller).

-- 
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/1167#issuecomment-928161284

Received on Monday, 27 September 2021 18:28:29 UTC