@@ -3171,6 +3171,7 @@ like
3171
3171
get <a href="#ws-locked">locked</a> ()
3172
3172
3173
3173
<a href="#ws-abort">abort</a> (reason)
3174
+ <a href="#ws-close">close</a> ()
3174
3175
<a href="#ws-get-writer">getWriter</a> ()
3175
3176
}
3176
3177
</code></pre>
@@ -3385,6 +3386,25 @@ bridging the gap with non-promise-based APIs, as seen for example in [[#example-
3385
3386
1. Return ! WritableStreamAbort(*this*, _reason_).
3386
3387
</emu-alg>
3387
3388
3389
+ <h5 id="ws-close" method for="WritableStream">close()</h5>
3390
+
3391
+ <div class="note">
3392
+ The <code> close</code> method closes the stream. The <a>underlying sink</a> will finish processing any
3393
+ previously-written <a>chunks</a> , before invoking its close behavior. During this time any further attempts to write
3394
+ will fail (without erroring the stream).
3395
+
3396
+ The method returns a promise that is fulfilled with <emu-val> undefined</emu-val> if all remaining <a>chunks</a> are
3397
+ successfully written and the stream successfully closes, or rejects if an error is encountered during this process.
3398
+ </div>
3399
+
3400
+ <emu-alg>
3401
+ 1. If ! IsWritableStream(*this*) is *false*, return <a>a promise rejected with</a> a *TypeError* exception.
3402
+ 1. If ! IsWritableStreamLocked(*this*) is *true*, return <a>a promise rejected with</a> a *TypeError* exception.
3403
+ 1. If ! WritableStreamCloseQueuedOrInFlight(*this*) is *true*, return <a>a promise rejected with</a> a *TypeError*
3404
+ exception.
3405
+ 1. Return ! WritableStreamClose(*this*).
3406
+ </emu-alg>
3407
+
3388
3408
<h5 id="ws-get-writer" method for="WritableStream">getWriter()</h5>
3389
3409
3390
3410
<div class="note">
@@ -3490,6 +3510,22 @@ writable stream is <a>locked to a writer</a>.
3490
3510
1. Return _promise_.
3491
3511
</emu-alg>
3492
3512
3513
+ <h4 id="writable-stream-close" aoid="WritableStreamClose" nothrow>WritableStreamClose ( <var>stream</var> )</h4>
3514
+
3515
+ <emu-alg>
3516
+ 1. Let _state_ be _stream_.[[state]] .
3517
+ 1. If _state_ is `"closed"` or `"errored"`, return <a>a promise rejected with</a> a *TypeError* exception.
3518
+ 1. Assert: _state_ is `"writable"` or `"erroring"`.
3519
+ 1. Assert: ! WritableStreamCloseQueuedOrInFlight(_stream_) is *false*.
3520
+ 1. Let _promise_ be <a>a new promise</a> .
3521
+ 1. Set _stream_.[[closeRequest]] to _promise_.
3522
+ 1. Let _writer_ be _stream_.[[writer]] .
3523
+ 1. If _writer_ is not *undefined*, and _stream_.[[backpressure]] is *true*, and _state_ is `"writable"`,
3524
+ <a>resolve</a> _writer_.[[readyPromise]] with *undefined*.
3525
+ 1. Perform ! WritableStreamDefaultControllerClose(_stream_.[[writableStreamController]] ).
3526
+ 1. Return _promise_.
3527
+ </emu-alg>
3528
+
3493
3529
<h3 id="ws-abstract-ops-used-by-controllers">Writable stream abstract operations used by controllers</h3>
3494
3530
3495
3531
To allow future flexibility to add different writable stream behaviors (similar to the distinction between default
@@ -3853,12 +3889,8 @@ lt="WritableStreamDefaultWriter(stream)">new WritableStreamDefaultWriter(<var>st
3853
3889
<h5 id="default-writer-close" method for="WritableStreamDefaultWriter">close()</h5>
3854
3890
3855
3891
<div class="note">
3856
- The <code> close</code> method will close the associated writable stream. The <a>underlying sink</a> will finish
3857
- processing any previously-written <a>chunks</a> , before invoking its close behavior. During this time any further
3858
- attempts to write will fail (without erroring the stream).
3859
-
3860
- The method returns a promise that is fulfilled with <emu-val> undefined</emu-val> if all remaining <a>chunks</a> are
3861
- successfully written and the stream successfully closes, or rejects if an error is encountered during this process.
3892
+ If the writer is <a lt="active writer">active</a> , the <code> close</code> method behaves the same as that for the
3893
+ associated stream. (Otherwise, it returns a rejected promise.)
3862
3894
</div>
3863
3895
3864
3896
<emu-alg>
@@ -3936,16 +3968,7 @@ nothrow>WritableStreamDefaultWriterClose ( <var>writer</var> )</h4>
3936
3968
<emu-alg>
3937
3969
1. Let _stream_ be _writer_.[[ownerWritableStream]] .
3938
3970
1. Assert: _stream_ is not *undefined*.
3939
- 1. Let _state_ be _stream_.[[state]] .
3940
- 1. If _state_ is `"closed"` or `"errored"`, return <a>a promise rejected with</a> a *TypeError* exception.
3941
- 1. Assert: _state_ is `"writable"` or `"erroring"`.
3942
- 1. Assert: ! WritableStreamCloseQueuedOrInFlight(_stream_) is *false*.
3943
- 1. Let _promise_ be <a>a new promise</a> .
3944
- 1. Set _stream_.[[closeRequest]] to _promise_.
3945
- 1. If _stream_.[[backpressure]] is *true* and _state_ is `"writable"`, <a>resolve</a> _writer_.[[readyPromise]] with
3946
- *undefined*.
3947
- 1. Perform ! WritableStreamDefaultControllerClose(_stream_.[[writableStreamController]] ).
3948
- 1. Return _promise_.
3971
+ 1. Return ! WritableStreamClose(_stream_).
3949
3972
</emu-alg>
3950
3973
3951
3974
<h4 id="writable-stream-default-writer-close-with-error-propagation" aoid="WritableStreamDefaultWriterCloseWithErrorPropagation"
0 commit comments