Open
Conversation
Support vectored writes of sync iterables of bytes sources.
7f53d0a to
87a1c98
Compare
harrishancock
approved these changes
Feb 18, 2026
| // is in progress. | ||
| // | ||
| // The returned promise will never resolve with more than maxBytes. | ||
| // The returned promise will never resolve with more than maxBytes |
Collaborator
There was a problem hiding this comment.
Suggested change
| // The returned promise will never resolve with more than maxBytes | |
| // The returned promise will never resolve with more than maxBytes. |
| KJ_IF_SOME(fn, val.tryCast<JsFunction>()) { | ||
| return Signature([fn = JsRef(js, fn), obj = JsRef(js, object)]( | ||
| jsg::Lock& js, Optional<JsValue> arg) -> GeneratorNext<JsValue> { | ||
| return js.tryCatch([&]() -> GeneratorNext<JsValue> { |
Collaborator
There was a problem hiding this comment.
Here and elsewhere, you could use JSG_TRY / JSG_CATCH for new code now, if you want.
| // or ArrayBufferView, we will attempt to detach the underlying buffer | ||
| // before writing it to the sink. Detaching is required by the | ||
| // streams spec but our original implementation does not detach | ||
| // and it turns out there are old workers depending on that behavior. |
Collaborator
There was a problem hiding this comment.
Do we need to worry about old workers still? My understanding it's a moot point whether we detach or not, because we have to use a non-V8 heap buffer anyway, but if detaching versus not detaching is a script-visible side effect, could removing this break anyone?
| while (true) { | ||
| KJ_IF_SOME(next, gen.next(js)) { | ||
| JSG_REQUIRE( | ||
| pieces.size() <= 64, TypeError, "Too many pieces yielded from the iterable."); |
Collaborator
There was a problem hiding this comment.
Nit: would be good to note the current limit in the error message
| // this and make sure we are properly handling those cases. | ||
| // TODO(later): We can possibly optimize this by getting the memory protection key and | ||
| // avoiding the copy. | ||
| return js.tryCatch([&]() -> jsg::Promise<void> { |
Collaborator
There was a problem hiding this comment.
Nit: could be JSG_TRY
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A number of cleanups and more improvements.
For the write adapter, when writing to an internal stream (think fetch, identity transform stream, etc)... we will directly support writing
ArrayBuffer,ArrayBufferView,SharedArrayBufferlike we do currently, but we also support writing strings directly (as utf8 bytes) which will avoid hving to create aTextEncoder. And we'll also support writing sync iterables, e.g.Why you ask? Pretty simple.. writing multiple chunks at once will help avoid the more expensive KJ/JS promise loop.