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
"await writer.write(bytes);" in example seems wrong #874
Comments
It should not be awaiting on writer.write() in addition to writer.ready. Closes #874.
Sorry, I really should have responded to this sooner. Because the Additionally, if we don't wait on await writer.ready; // ensure desiredSize > 0
while (true) {
const bytes = new Uint8Array(writer.desiredSize);
window.crypto.getRandomValues(bytes);
await writer.write(bytes);
} Except now it's not a good example of while (true) {
await writer.ready;
const bytes = new Uint8Array(1024);
window.crypto.getRandomValues(bytes);
writer.write(bytes).catch(() => {});
} ? Oh, but we're also trying to demonstrate By the way, why is it |
Oh, right, in this particular example it is the same, good point. Hmm. I'd still like to not encourage waiting on writer.write() as except in cases where you're explicitly using desiredSize, it's not a good idea. This may benefit from two examples, one to demonstrate desiredSize and one to demonstrate how if you don't use desiredSize, ready and write() will get out of sync. And yeah, we should get rid of the |
It should not be awaiting on writer.write() in addition to writer.ready. Closes #874.
https://streams.spec.whatwg.org/#example-manual-write-with-backpressure
We're already awaiting writer.ready. Awaiting writer.write() seems counterproductive, as it means that even if the writable stream has a large high water mark, we won't be writing multiple chunks to fill the queue, instead waiting until every individual chunk has been processed sequentially.
The text was updated successfully, but these errors were encountered: