Fix 11494: promise handling in WritableStreamDefaultWriter example #25597
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.
Fixes #11494, I hope.
This PR rewrites the example to use
await
.In the issue report I was a bit puzzled by this bit:
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:defaultWriter.close();
should presumably return its promise, or any error is unhandledOne change I have made here is no longer distinguishing between a chunk write failing and
defaultWriter.close();
failing: they're all in the sametry
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:...and in this version it is like: