401
401
<a href="#rs-cancel">cancel</a> (reason)
402
402
<a href="#rs-get-reader">getReader</a> ()
403
403
<a href="#rs-pipe-through">pipeThrough</a> ({ writable, readable }, options)
404
- <a href="#rs-pipe-to">pipeTo</a> (dest, { preventClose, preventAbort, preventCancel } = {})
404
+ <a href="#rs-pipe-to">pipeTo</a> (dest, { preventClose, preventAbort, preventCancel, signal } = {})
405
405
<a href="#rs-tee">tee</a> ()
406
406
}
407
407
</code></pre>
@@ -701,8 +701,9 @@ option. If <code><a for="underlying source">type</a></code> is set to <code>unde
701
701
</code></pre>
702
702
</div>
703
703
704
- <h5 id="rs-pipe-to" method for="ReadableStream" lt="pipeTo(dest, options)">pipeTo(<var ignore>dest</var>, {
705
- <var ignore>preventClose</var>, <var ignore>preventAbort</var>, <var ignore>preventCancel</var> } = {})</h5>
704
+ <h5 id="rs-pipe-to" method for="ReadableStream" lt="pipeTo(dest, options)">pipeTo(<var ignore>dest</var>,
705
+ { <var ignore>preventClose</var>, <var ignore>preventAbort</var>, <var ignore>preventCancel</var>,
706
+ <var ignore>signal</var> } = {})</h5>
706
707
707
708
<div class="note">
708
709
The <code> pipeTo</code> method <a lt="piping">pipes</a> this <a>readable stream</a> to a given <a>writable
@@ -733,13 +734,21 @@ option. If <code><a for="underlying source">type</a></code> is set to <code>unde
733
734
promise will be rejected with an error indicating piping to a closed stream failed, or with any error that occurs
734
735
during canceling the source.</p></li>
735
736
</ul>
737
+
738
+ The <code> signal</code> option can be set to an {{AbortSignal}} to allow aborting an ongoing pipe operation via the
739
+ corresponding {{AbortController}} . In this case, the source <a>readable stream</a> will be <a lt="cancel a readable
740
+ stream">canceled</a> , and the destination <a>writable stream</a> <a lt="abort a writable stream">aborted</a> , unless
741
+ the respective options <code> preventCancel</code> or <code> preventAbort</code> are set.
742
+
736
743
</div>
737
744
738
745
<emu-alg>
739
746
1. If ! IsReadableStream(*this*) is *false*, return <a>a promise rejected with</a> a *TypeError* exception.
740
747
1. If ! IsWritableStream(_dest_) is *false*, return <a>a promise rejected with</a> a *TypeError* exception.
741
748
1. Set _preventClose_ to ! ToBoolean(_preventClose_), set _preventAbort_ to ! ToBoolean(_preventAbort_), and set
742
749
_preventCancel_ to ! ToBoolean(_preventCancel_).
750
+ 1. If _signal_ is not *undefined*, and _signal_ is not an instance of the `<a idl>AbortSignal</a> ` interface, return
751
+ <a>a promise rejected with</a> a *TypeError* exception.
743
752
1. If ! IsReadableStreamLocked(*this*) is *true*, return <a>a promise rejected with</a> a *TypeError* exception.
744
753
1. If ! IsWritableStreamLocked(_dest_) is *true*, return <a>a promise rejected with</a> a *TypeError* exception.
745
754
1. If ! IsReadableByteStreamController(*this*.[[readableStreamController]] ) is *true*, let _reader_ be either !
@@ -749,6 +758,20 @@ option. If <code><a for="underlying source">type</a></code> is set to <code>unde
749
758
1. Let _writer_ be ! AcquireWritableStreamDefaultWriter(_dest_).
750
759
1. Let _shuttingDown_ be *false*.
751
760
1. Let _promise_ be <a>a new promise</a> .
761
+ 1. If _signal_ is not *undefined*,
762
+ 1. Let _abortAlgorithm_ be the following steps:
763
+ 1. Let _error_ be a new "`<a idl>AbortError</a> `" `<a idl>DOMException</a> `.
764
+ 1. Let _actions_ be an empty <a>ordered set</a> .
765
+ 1. If _preventAbort_ is *false*, <a for="set">append</a> the following action to _actions_:
766
+ 1. If _dest_.[[_state_]] is `"writable"`, return ! WritableStreamAbort(_dest_, _error_).
767
+ 1. Otherwise, return <a>a promise resolved with</a> *undefined*.
768
+ 1. If _preventCancel_ is *false*, <a for="set">append</a> the following action action to _actions_:
769
+ 1. If *this*.[[_state_]] is `"readable"`, return ! ReadableStreamCancel(*this*, _error_).
770
+ 1. Otherwise, return <a>a promise resolved with</a> *undefined*.
771
+ 1. <a href="#rs-pipeTo-shutdown-with-action">Shutdown with an action</a> consisting of <a>waiting for all</a>
772
+ of the actions in _actions_, and with _error_.
773
+ 1. If _signal_'s <a for=AbortSignal>aborted flag</a> is set, perform _abortAlgorithm_ and return _promise_.
774
+ 1. <a for="AbortSignal">Add</a> _abortAlgorithm_ to _signal_.
752
775
1. <a>In parallel</a> <span class="XXX"> but not really; see <a
753
776
href="https://github.com/whatwg/streams/issues/905"> #905</a></span> , using _reader_ and _writer_, read all
754
777
<a>chunks</a> from *this* and write them to _dest_. Due to the locking provided by the reader and writer, the exact
@@ -817,6 +840,7 @@ option. If <code><a for="underlying source">type</a></code> is set to <code>unde
817
840
an error _error_, which means to perform the following steps:
818
841
1. Perform ! WritableStreamDefaultWriterRelease(_writer_).
819
842
1. Perform ! ReadableStreamReaderGenericRelease(_reader_).
843
+ 1. If _signal_ is not *undefined*, <a for="AbortSignal">remove</a> _abortAlgorithm_ from _signal_.
820
844
1. If _error_ was given, <a>reject</a> _promise_ with _error_.
821
845
1. Otherwise, <a>resolve</a> _promise_ with *undefined*.
822
846
1. Return _promise_.
0 commit comments