-
Notifications
You must be signed in to change notification settings - Fork 163
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
Add WritableStream#write convenience method #1339
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4064,6 +4064,7 @@ interface WritableStream { | |
|
||
readonly attribute boolean locked; | ||
|
||
Promise<undefined> write(optional any chunk); | ||
Promise<undefined> abort(optional any reason); | ||
Promise<undefined> close(); | ||
WritableStreamDefaultWriter getWriter(); | ||
|
@@ -4270,6 +4271,17 @@ as seen for example in [[#example-ws-no-backpressure]]. | |
<dd> | ||
<p>Returns whether or not the writable stream is [=locked to a writer=]. | ||
|
||
<dt><code>await <var ignore>stream</var>.{{WritableStream/write(chunk)|write}}([ <var ignore>chunk</var> ])</code> | ||
<dd> | ||
<p>Writes a [=chunk=] of data to the stream just like the {{WritableStreamDefaultWriter/write()}} | ||
method. | ||
|
||
<p>This is a convenience method that first acquires a writer, queues the chunk to be written, | ||
releases the writer (without waiting on the write to complete), and returns a promise that | ||
fulfills if the write was successful, or reject if the write failed. Additionally, if the stream | ||
is currently [=locked to a writer|locked=], a promise rejecting with a {{TypeError}} is returned, | ||
and no attempt to write will be made. | ||
|
||
<dt><code>await <var ignore>stream</var>.{{WritableStream/abort(reason)|abort}}([ <var ignore>reason</var> ])</code> | ||
<dd> | ||
<p>[=abort a writable stream|Aborts=] the stream, signaling that the producer can no longer | ||
|
@@ -4332,6 +4344,17 @@ as seen for example in [[#example-ws-no-backpressure]]. | |
1. Return ! [$IsWritableStreamLocked$]([=this=]). | ||
</div> | ||
|
||
<div algorithm> | ||
The <dfn id="ws-write" method for="WritableStream">write(|chunk|)</dfn> method steps are: | ||
lucacasonato marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
1. Let |result| be ? [$AcquireWritableStreamDefaultWriter$]([=this=]). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be worth introducing a new abstract op (We may have to take There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will do that if I can get implementer interest :) |
||
1. If |result| is an abrupt completion, return [=a promise rejected with=] |result|.\[[Value]]. | ||
1. Let |writer| be |result|.\[[Value]]. | ||
1. Let |writePromise| be ! [$WritableStreamDefaultWriterWrite$](|writer|, |chunk|). | ||
1. Perform ! [$WritableStreamDefaultWriterRelease$](|writer|). | ||
1. Return |writePromise|. | ||
</div> | ||
|
||
<div algorithm> | ||
The <dfn id="ws-abort" method for="WritableStream">abort(|reason|)</dfn> method steps are: | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor nit: