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

Fix 11494: promise handling in WritableStreamDefaultWriter example #25597

Merged
merged 2 commits into from
Mar 26, 2023

Conversation

wbamberg
Copy link
Collaborator

@wbamberg wbamberg commented Mar 24, 2023

Fixes #11494, I hope.

This PR rewrites the example to use await.

In the issue report I was a bit puzzled by this bit:

defaultWriter.ready.then is called multiple times.

As far as I can see you have to call ready after each time you write to the stream, so you know you can write to it again. However it is true that:

  • if any chunk write throws an error, then the writer keeps writing (and keeps getting errors), when it should presumably give up
  • defaultWriter.close(); should presumably return its promise, or any error is unhandled

One change I have made here is no longer distinguishing between a chunk write failing and defaultWriter.close(); failing: they're all in the same try block. That is simpler and seemed OK?

Anyway if you like this I'll update all the other places it's used, as well as the working copy in mdn/dom-examples.

I've tested this and it seems to work fine. I've also tested it with write throwing an error: in the old version the output was like:


Screen Shot 2023-03-23 at 10 20 31 PM


...and in this version it is like:


Screen Shot 2023-03-23 at 10 20 54 PM

@wbamberg wbamberg requested a review from a team as a code owner March 24, 2023 05:23
@wbamberg wbamberg requested review from sideshowbarker and removed request for a team March 24, 2023 05:23
@github-actions github-actions bot added the Content:WebAPI Web API docs label Mar 24, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Mar 24, 2023

Preview URLs

(comment last updated: 2023-03-24 05:35:49)

Copy link
Contributor

@teoli2003 teoli2003 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much better, and demonstrates how await improve code readability, too. I'm not merging it in case others want to review it, but feel free to merge it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:WebAPI Web API docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue with "WritableStreamDefaultWriter": (Incorrect/Problematic Example)
3 participants