Skip to content

Commit 0a3de95

Browse files
committed
Use tasks to manipulate streams
Helps with #1246. The main problem with this PR (which is why I marked it WIP) is that the stream itself is created in parallel and I don't see a good way to avoid that. If we had low-level streams this would be different.
1 parent 613aad9 commit 0a3de95

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

fetch.bs

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4199,9 +4199,7 @@ steps:
41994199
<p><a>If aborted</a>, then:
42004200

42014201
<ol>
4202-
<li><p>Let <var>aborted</var> be the termination's aborted flag.
4203-
4204-
<li><p>If <var>aborted</var> is set, then return an <a>aborted network error</a>.
4202+
<li><p>If the termination's aborted flag is set, then return an <a>aborted network error</a>.
42054203

42064204
<li><p>Return a <a>network error</a>.
42074205
</ol>
@@ -4937,9 +4935,7 @@ steps. They return a <a for=/>response</a>.
49374935
<p><a>If aborted</a>, then:
49384936

49394937
<ol>
4940-
<li><p>Let <var>aborted</var> be the termination's aborted flag.
4941-
4942-
<li><p>If <var>aborted</var> is set, then return an <a>aborted network error</a>.
4938+
<li><p>If the termination's aborted flag is set, then return an <a>aborted network error</a>.
49434939

49444940
<li><p>Return a <a>network error</a>.
49454941
</ol>
@@ -5039,9 +5035,7 @@ steps. They return a <a for=/>response</a>.
50395035
<p>If the ongoing fetch is <a for=fetch>terminated</a>, then:
50405036

50415037
<ol>
5042-
<li><p>Let <var>aborted</var> be the termination's aborted flag.
5043-
5044-
<li><p>If <var>aborted</var> is set, then return an <a>aborted network error</a>.
5038+
<li><p>If the termination's aborted flag is set, then return an <a>aborted network error</a>.
50455039

50465040
<li><p>Return a <a>network error</a>.
50475041
</ol>
@@ -5075,9 +5069,7 @@ steps. They return a <a for=/>response</a>.
50755069
<p>If the ongoing fetch is <a for=fetch>terminated</a>, then:
50765070

50775071
<ol>
5078-
<li><p>Let <var>aborted</var> be the termination's aborted flag.
5079-
5080-
<li><p>If <var>aborted</var> is set, then return an <a>aborted network error</a>.
5072+
<li><p>If the termination's aborted flag is set, then return an <a>aborted network error</a>.
50815073

50825074
<li><p>Return a <a>network error</a>.
50835075
</ol>
@@ -5113,9 +5105,7 @@ steps. They return a <a for=/>response</a>.
51135105
<p>If the ongoing fetch is <a for=fetch>terminated</a>, then:
51145106

51155107
<ol>
5116-
<li><p>Let <var>aborted</var> be the termination's aborted flag.
5117-
5118-
<li><p>If <var>aborted</var> is set, then return an <a>aborted network error</a>.
5108+
<li><p>If the termination's aborted flag is set, then return an <a>aborted network error</a>.
51195109

51205110
<li><p>Return a <a>network error</a>.
51215111
</ol>
@@ -5320,11 +5310,9 @@ optional boolean <var>forceNewConnection</var> (default false), run these steps:
53205310
<p><a>If aborted</a>, then:
53215311

53225312
<ol>
5323-
<li><p>Let <var>aborted</var> be the termination's aborted flag.
5324-
53255313
<li><p>If <var>connection</var> uses HTTP/2, then transmit an <code>RST_STREAM</code> frame.
53265314

5327-
<li><p>If <var>aborted</var> is set, then return an <a>aborted network error</a>.
5315+
<li><p>If the termination's aborted flag is set, then return an <a>aborted network error</a>.
53285316

53295317
<li><p>Return a <a>network error</a>.
53305318
</ol>
@@ -5378,9 +5366,7 @@ optional boolean <var>forceNewConnection</var> (default false), run these steps:
53785366
<p><a>If aborted</a>, then:
53795367

53805368
<ol>
5381-
<li><p>Let <var>aborted</var> be the termination's aborted flag.
5382-
5383-
<li><p>If <var>aborted</var> is set, then set <var>response</var>'s
5369+
<li><p>If the termination's aborted flag is set, then set <var>response</var>'s
53845370
<a for=response>aborted flag</a>.
53855371

53865372
<li><p>Return <var>response</var>.
@@ -5423,20 +5409,28 @@ optional boolean <var>forceNewConnection</var> (default false), run these steps:
54235409
<li><p>If <var>bytes</var> is failure, then <a lt=terminated for=fetch>terminate</a> the
54245410
ongoing fetch.
54255411

5426-
<li><p><a for=ReadableStream>Enqueue</a> a {{Uint8Array}} wrapping an {{ArrayBuffer}}
5427-
containing <var>bytes</var> into <var>stream</var>.
5412+
<li>
5413+
<p>Let <var>handleResponseBytes</var> be these steps:
54285414

5429-
<li><p>If <var>stream</var> is <a for=ReadableStream>errored</a>, then
5430-
<a lt=terminated for=fetch>terminate</a> the ongoing fetch.
5415+
<ol>
5416+
<li><p><a for=ReadableStream>Enqueue</a> a {{Uint8Array}} wrapping an {{ArrayBuffer}}
5417+
containing <var>bytes</var> into <var>stream</var>.
54315418

5432-
<li><p>If <var>stream</var> doesn't <a for=ReadableStream>need more data</a> ask the user
5433-
agent to <a for=fetch>suspend</a> the ongoing fetch.
5419+
<li><p>If <var>stream</var> is <a for=ReadableStream>errored</a>, then
5420+
<a lt=terminated for=fetch>terminate</a> the ongoing fetch.
5421+
5422+
<li><p>If <var>stream</var> doesn't <a for=ReadableStream>need more data</a> ask the user
5423+
agent to <a for=fetch>suspend</a> the ongoing fetch.
5424+
</ol>
5425+
5426+
<li><p>Otherwise, if the bytes transmission for <var>response</var>'s message body is done
5427+
normally and <var>stream</var> is <a for=ReadableStream>readable</a>, then
5428+
<a for=ReadableStream>close</a> <var>stream</var>, <a for=/>finalize response</a> for
5429+
<var>fetchParams</var> and <var>response</var>.
54345430
</ol>
54355431

5436-
<li><p>Otherwise, if the bytes transmission for <var>response</var>'s message body is done
5437-
normally and <var>stream</var> is <a for=ReadableStream>readable</a>, then
5438-
<a for=ReadableStream>close</a> <var>stream</var>, <a for=/>finalize response</a> for
5439-
<var>fetchParams</var> and <var>response</var>, and abort these in-parallel steps.
5432+
<li><p><a>Queue a fetch task</a> given <var>handleResponseBytes</var> and
5433+
<var>fetchParams</var>'s <a for="fetch params">task destination</a>.
54405434
</ol>
54415435
</ol>
54425436

@@ -5446,22 +5440,6 @@ optional boolean <var>forceNewConnection</var> (default false), run these steps:
54465440
<ol>
54475441
<li><a for=/>Finalize response</a> for <var>fetchParams</var> and <var>response</var>.
54485442

5449-
<li><p>Let <var>aborted</var> be the termination's aborted flag.
5450-
5451-
<li>
5452-
<p>If <var>aborted</var> is set, then:
5453-
5454-
<ol>
5455-
<li><p>Set <var>response</var>'s <a for=response>aborted flag</a>.
5456-
5457-
<li><p>If <var>stream</var> is <a for=ReadableStream>readable</a>,
5458-
<a for=ReadableStream>error</a> <var>stream</var> with an
5459-
"<code><a exception>AbortError</a></code>" {{DOMException}}.
5460-
</ol>
5461-
5462-
<li><p>Otherwise, if <var>stream</var> is <a for=ReadableStream>readable</a>,
5463-
<a for=ReadableStream>error</a> <var>stream</var> with a {{TypeError}}.
5464-
54655443
<li><p>If <var>connection</var> uses HTTP/2, then transmit an <code>RST_STREAM</code> frame.
54665444

54675445
<li>
@@ -5471,6 +5449,28 @@ optional boolean <var>forceNewConnection</var> (default false), run these steps:
54715449
<p class=note>For instance, the user agent could keep the connection open if it knows there's
54725450
only a few bytes of transfer remaining on a reusable connection. In this case it could be
54735451
worse to close the connection and go through the handshake process again for the next fetch.
5452+
5453+
<li>
5454+
<p>Let <var>handleResponseError</var> be these steps:
5455+
5456+
<ol>
5457+
<li>
5458+
<p>If the termination's aborted flag is set, then:
5459+
5460+
<ol>
5461+
<li><p>Set <var>response</var>'s <a for=response>aborted flag</a>.
5462+
5463+
<li><p>If <var>stream</var> is <a for=ReadableStream>readable</a>,
5464+
<a for=ReadableStream>error</a> <var>stream</var> with an
5465+
"<code><a exception>AbortError</a></code>" {{DOMException}}.
5466+
</ol>
5467+
5468+
<li><p>Otherwise, if <var>stream</var> is <a for=ReadableStream>readable</a>,
5469+
<a for=ReadableStream>error</a> <var>stream</var> with a {{TypeError}}.
5470+
</ol>
5471+
5472+
<li><p><a>Queue a fetch task</a> given <var>handleResponseError</var> and
5473+
<var>fetchParams</var>'s <a for="fetch params">task destination</a>.
54745474
</ol>
54755475
</ol>
54765476

0 commit comments

Comments
 (0)