Skip to content

Commit 7d31a8c

Browse files
committed
Introduce AbortSignal.timeout()
Closes #951.
1 parent 4ca187f commit 7d31a8c

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

dom.bs

+36-2
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,7 @@ The API which wishes to support aborting can accept an {{AbortSignal}} object, a
16681668
determine how to proceed.
16691669

16701670
<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=].
16721672

16731673
<div class=example id=aborting-ongoing-activities-example>
16741674
<p>A hypothetical <code>doAmazingness({ ... })</code> method could accept an {{AbortSignal}} object
@@ -1705,7 +1705,7 @@ function doAmazingness({signal}) {
17051705
// But also, watch for signals:
17061706
signal.addEventListener('abort', () => {
17071707
// Stop doing amazingness, and:
1708-
reject(new DOMException('Aborted', 'AbortError'));
1708+
reject(signal.reason);
17091709
});
17101710
});
17111711
}
@@ -1770,6 +1770,7 @@ to <a for=AbortSignal>signal abort</a> on <a>this</a>'s <a for=AbortController>s
17701770
[Exposed=(Window,Worker)]
17711771
interface AbortSignal : EventTarget {
17721772
[NewObject] static AbortSignal abort(optional any reason);
1773+
[NewObject] static AbortSignal timeout([EnforceRange] unsigned long long milliseconds);
17731774

17741775
readonly attribute boolean aborted;
17751776
readonly attribute any reason;
@@ -1782,6 +1783,11 @@ interface AbortSignal : EventTarget {
17821783
<dd>Returns an {{AbortSignal}} instance whose <a for=AbortSignal>abort reason</a> is set to
17831784
<var>reason</var> if not undefined; otherwise to an "{{AbortError!!exception}}" {{DOMException}}.
17841785

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+
17851791
<dt><code><var>signal</var> . <a attribute for=AbortSignal>aborted</a></code>
17861792
<dd>Returns true if this {{AbortSignal}}'s {{AbortController}} has signaled to abort; otherwise
17871793
false.
@@ -1831,6 +1837,34 @@ are:
18311837
<li>Return <var>signal</var>.
18321838
</ol>
18331839

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+
18341868
<p>The <dfn attribute for=AbortSignal>aborted</dfn> getter steps are to return true if <a>this</a>
18351869
is [=AbortSignal/aborted=]; otherwise false.
18361870

0 commit comments

Comments
 (0)