Re: [whatwg/streams] Add support for ReadableStream "owning" type (PR #1271)

@jasnell That would imply that a stream can hold both "owned" and "unowned" chunks at the same time. This would mean a bunch more bookkeeping and passing around extra parameters:

* The stream's queue would need to record for each chunk whether it is owned or not, so `ResetQueue` knows to *only* call the dispose steps on owned chunks. We'll need to extend [value-with-size](https://streams.spec.whatwg.org/#value-with-size) to have an extra *isOwned* item.
* `ReadableStreamTee` would no longer unconditionally clone chunks to both branches. Instead, it needs to first check for each chunk received from the original stream whether it was owned or not. We'd need to extend [read request's chunk steps](https://streams.spec.whatwg.org/#read-request-chunk-steps) to have an extra parameter *isOwned* to store that information.
  * Should this information be exposed through `ReadableStreamDefaultReader.read()` too? Something like returning a `{ done, value, owned }` tuple instead? (This is probably a very bad idea... 😅)
* `TransformStreamDefaultController` would need the same treatment, and get a `clone()` method.
* We would need to extend this to `WritableStream` too, e.g. `WritableStreamDefaultWriter.writeCloned(chunk, { transfer: [] })` or `.write(chunk, { clone: true, transfer: [] })`
* Would we need to inform a `WritableStream`'s sink or a `TransformStream`'s transformer that a written chunk is now owned by the stream, in case it wants to forward that chunk to `Readable|TransformStreamDefaultController.clone()`? That would mean passing an *isOwned* parameter to `sink.write()` or `transformer.transform()` somehow... 😕

All in all, I think it's easier to have a separate type for owning streams.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/pull/1271#issuecomment-2102473839
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/streams/pull/1271/c2102473839@github.com>

Received on Thursday, 9 May 2024 11:20:57 UTC