-
Notifications
You must be signed in to change notification settings - Fork 9.3k
[Workers] Document streams_byob_reader_detaches_buffer compatibility flag #2644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Workers] Document streams_byob_reader_detaches_buffer compatibility flag #2644
Conversation
…flag This compatibility flag is new as of this week. Note that the text references a relatively new, non-standard method that we added to ReadableStream: `readAtLeast()`. Unfortunately, this method is not yet documented.
|
||
Originally, the Workers runtime did not detach the `ArrayBuffer`s from user-provided TypedArrays when using the [BYOB reader's `read()` method](/runtime-apis/streams/readablestreambyobreader#methods), as required by the Streams spec, meaning it was possible to inadvertently reuse the same buffer for multiple `read()` calls. This change brings us in line with the spec. | ||
|
||
User code should never try to reuse an `ArrayBuffer` that has been passed into a [BYOB reader's `read()` method](/runtime-apis/streams/readablestreambyobreader#methods). The more recently added extension method `readAtLeast()` will always detach the `ArrayBuffer` and is unaffected by this feature flag setting. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can reuse the buffer, just not under the same reference? That is, when read()
returns, it gives you a new reference to the buffer, which you can then use in the next call. This seems like the whole point of BYOB, to avoid allocation overhead, so we should probably be a bit clearer here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a little example.
Sorry for failing to see this earlier, I have this repo muted because it was sending me too many notifications that weren't relevant to me... but that means I also missed a code review I was actually tagged on. :( |
a3d1b4b
to
67b5c61
Compare
67b5c61
to
e9f0839
Compare
LGTM but I guess my approval is not good enough as I'm not an owner. |
This compatibility flag is new as of this week.
Note that the text references a relatively new, non-standard method that we added to ReadableStream:
readAtLeast()
. Unfortunately, this method is not yet documented./cc @jasnell