Skip to content
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

Proposal: writev equivalent WritableStreamDefaultWriter #1309

Closed
jasnell opened this issue Mar 23, 2024 · 2 comments
Closed

Proposal: writev equivalent WritableStreamDefaultWriter #1309

jasnell opened this issue Mar 23, 2024 · 2 comments
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest

Comments

@jasnell
Copy link

jasnell commented Mar 23, 2024

What problem are you trying to solve?

Today, writing multiple values at once to a WritableStream is not generally possible or efficient. Each individual call to write(...) assumes a single value, with a single promise returned per value.

What solutions exist today?

Node.js stream.Writable offers both write(...) and writev(...) options. The write(...) takes a single value while writev(...) takes multiple.

How would you solve it?

Introduce a new writev(...) method to WritableStreamDefaultWriter (or something similar)

So instead of something like...

const writable = getWritableStreamSomehow();
const writer = writable.getWriter();
await Promise.all([
  writer.write('hello'),
  writer.write('world'),
  writer.write('!!!'),
]);  // Creates at least four promises...

We could simply (and efficiently do)

const writable = getWritableStreamSomehow();
const writer = writable.getWriter();
await writer.writev(['hello', 'world', '!!!']);  // Creates only one promise

The writev(...) method would accept any iterable or async-iterable as the input.

Anything else?

No response

@jasnell jasnell added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest labels Mar 23, 2024
@domenic
Copy link
Member

domenic commented Mar 23, 2024

Dupe of #27.

@domenic domenic closed this as completed Mar 23, 2024
@jasnell
Copy link
Author

jasnell commented Mar 23, 2024

Hmmm, #27 appears to be quite old and stale at this point, and the approach discussed here is fairly different (focusing only on adding writev to the existing WritableStreamDefaultWriter. Yes there is overlap in the problem space but I don't really agree that this is a duplicate of that issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest
Development

No branches or pull requests

2 participants