Re: [whatwg/streams] Returning buffers to the underlying source (Issue #1217)

@yume-chan makes a great point. This pattern is already possible without making any changes to the streams API by passing a type that explicitly supports this behavior through the stream.

```js
for await (const chunk of readable) {
  // use chunk
  chunk.release();
}
```

I can see a number of complexities in the other proposed methods that make them undesirable. For instance, given @domenic's [example](https://github.com/whatwg/streams/issues/1217#issuecomment-1035678402):

```
const { done: done1, value: value1, release: release1 } = await reader.read();

// ... later ...
release1();
```

If `value` is a transferable value (like an `ArrayBuffer` or `TypedArray`, then the consuming code can simply transfer that away to some other place. What would the semantics of `release()` be in that case? There's also no guarantee that the consuming code will process the results of each read in any predictable order, which further complicates things.

All of the edge cases here are complex enough that, for this behavior, it would be better for users to devise their own type with acquire-use-then-release semantics.

tl;dr is I don't think this idea is something we should bake into the spec.

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

Message ID: <whatwg/streams/issues/1217/1154044403@github.com>

Received on Monday, 13 June 2022 15:09:25 UTC