@@ -1668,7 +1668,7 @@ The API which wishes to support aborting can accept an {{AbortSignal}} object, a
1668
1668
determine how to proceed.
1669
1669
1670
1670
<p> APIs that rely upon {{AbortController}} are encouraged to respond to {{AbortController/abort()}}
1671
- by rejecting any unsettled promise with a new " {{AbortError!!exception}} " {{DOMException}} .
1671
+ by rejecting any unsettled promise with the {{AbortSignal}} 's [=AbortSignal/abort reason=] .
1672
1672
1673
1673
<div class=example id=aborting-ongoing-activities-example>
1674
1674
<p> A hypothetical <code> doAmazingness({ ... })</code> method could accept an {{AbortSignal}} object
@@ -1705,7 +1705,7 @@ function doAmazingness({signal}) {
1705
1705
// But also, watch for signals:
1706
1706
signal.addEventListener('abort' , () => {
1707
1707
// Stop doing amazingness, and:
1708
- reject(new DOMException( 'Aborted' , 'AbortError' ) );
1708
+ reject(signal.reason );
1709
1709
});
1710
1710
});
1711
1711
}
@@ -1770,6 +1770,7 @@ to <a for=AbortSignal>signal abort</a> on <a>this</a>'s <a for=AbortController>s
1770
1770
[Exposed=(Window,Worker)]
1771
1771
interface AbortSignal : EventTarget {
1772
1772
[NewObject] static AbortSignal abort(optional any reason);
1773
+ [NewObject] static AbortSignal timeout([EnforceRange] unsigned long long milliseconds);
1773
1774
1774
1775
readonly attribute boolean aborted;
1775
1776
readonly attribute any reason;
@@ -1782,6 +1783,11 @@ interface AbortSignal : EventTarget {
1782
1783
<dd> Returns an {{AbortSignal}} instance whose <a for=AbortSignal>abort reason</a> is set to
1783
1784
<var> reason</var> if not undefined; otherwise to an "{{AbortError!!exception}} " {{DOMException}} .
1784
1785
1786
+ <dt><code> AbortSignal . <a method for=AbortSignal lt=timeout(milliseconds)>timeout</a> (<var> milliseconds</var> )</code>
1787
+ <dd> Returns an {{AbortSignal}} instance which will be aborted in <var> milliseconds</var>
1788
+ milliseconds. Its <a for=AbortSignal>abort reason</a> will be set to a
1789
+ "{{TimeoutError!!exception}} " {{DOMException}} .
1790
+
1785
1791
<dt><code><var> signal</var> . <a attribute for=AbortSignal>aborted</a> </code>
1786
1792
<dd> Returns true if this {{AbortSignal}} 's {{AbortController}} has signaled to abort; otherwise
1787
1793
false.
@@ -1831,6 +1837,34 @@ are:
1831
1837
<li> Return <var> signal</var> .
1832
1838
</ol>
1833
1839
1840
+ <p> The static <dfn method for=AbortSignal><code>timeout(<var>milliseconds</var>)</code></dfn> method
1841
+ steps are:
1842
+
1843
+ <ol>
1844
+ <li><p> Let <var> signal</var> be a new {{AbortSignal}} object.
1845
+
1846
+ <li><p> Let <var> global</var> be <var> signal</var> 's <a>relevant global object</a> .
1847
+
1848
+ <li>
1849
+ <p> Run these steps <a>in parallel</a> :
1850
+
1851
+ <ol>
1852
+ <li><p> Wait <var> milliseconds</var> milliseconds.
1853
+
1854
+ <li><p> Wait until any instances of these in-parallel steps that had the same <var> global</var> ,
1855
+ that started before this one, and whose <var> milliseconds</var> value is equal to or less than
1856
+ this one's, have completed.
1857
+
1858
+ <li><p> Optionally, wait a further <a>implementation-defined</a> amount of time.
1859
+
1860
+ <li><p> <a>Queue a global task</a> on the <a>timer task source</a> given <var> global</var> to
1861
+ <a for=AbortSignal>signal abort</a> given <var> signal</var> and a new
1862
+ "{{TimeoutError!!exception}} " {{DOMException}} .
1863
+ </ol>
1864
+
1865
+ <li> Return <var> signal</var> .
1866
+ </ol>
1867
+
1834
1868
<p> The <dfn attribute for=AbortSignal>aborted</dfn> getter steps are to return true if <a>this</a>
1835
1869
is [=AbortSignal/aborted=] ; otherwise false.
1836
1870
0 commit comments