Skip to content

Commit f894acd

Browse files
authored
Remove promises from "read all bytes"
This makes it easier for other specifications that use this algorithm, such as Fetch, to use streams while interfacing less directly with the JavaScript engine. Helps with whatwg/fetch#1568. Helps with #1178.
1 parent 839a5a6 commit f894acd

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

index.bs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6809,36 +6809,33 @@ a chunk</dfn> from a {{ReadableStreamDefaultReader}} |reader|, given a [=read re
68096809

68106810
<div algorithm="read all bytes">
68116811
<p>To <dfn export for="ReadableStreamDefaultReader" lt="read all bytes|reading all bytes">read all
6812-
bytes</dfn> from a {{ReadableStreamDefaultReader}} |reader|, perform the following steps. The
6813-
result will be a {{Promise}} for a [=byte sequence=].
6814-
6815-
1. Let |promise| be [=a new promise=].
6816-
1. Let |bytes| be an empty [=byte sequence=].
6817-
1. [=Read-loop=] given |reader|, |bytes|, and |promise|.
6818-
1. Return |promise|.
6812+
bytes</dfn> from a {{ReadableStreamDefaultReader}} |reader|, given |successSteps|,
6813+
which is an algorithm accepting a [=byte sequence=], and |failureSteps|, which is an algorithm
6814+
accepting a JavaScript value: [=read-loop=] given |reader|, a new [=byte sequence=],
6815+
|successSteps|, and |failureSteps|.
68196816

68206817
<div algorithm="read-loop">
6821-
For the purposes of the above algorithm, to <dfn>read-loop</dfn> given |reader|, |bytes|, and
6822-
|promise|:
6818+
For the purposes of the above algorithm, to <dfn>read-loop</dfn> given |reader|, |bytes|,
6819+
|successSteps|, and |failureSteps|:
68236820

68246821
1. Let |readRequest| be a new [=read request=] with the following [=struct/items=]:
68256822
: [=read request/chunk steps=], given |chunk|
68266823
::
6827-
1. If |chunk| is not a {{Uint8Array}} object, [=reject=] |promise| with a {{TypeError}} and
6824+
1. If |chunk| is not a {{Uint8Array}} object, call |failureSteps| with a {{TypeError}} and
68286825
abort these steps.
68296826
1. Append the bytes represented by |chunk| to |bytes|.
6830-
1. [=Read-loop=] given |reader|, |bytes|, and |promise|.
6827+
1. [=Read-loop=] given |reader|, |bytes|, |successSteps|, and |failureSteps|.
68316828
<p class="note">This recursion could potentially cause a stack overflow if implemented
68326829
directly. Implementations will need to mitigate this, e.g. by using a non-recursive variant
68336830
of this algorithm, or [=queue a microtask|queuing a microtask=], or using a more direct
68346831
method of byte-reading as noted below.
68356832

68366833
: [=read request/close steps=]
68376834
::
6838-
1. [=Resolve=] |promise| with |bytes|.
6835+
1. Call |successSteps| with |bytes|.
68396836
: [=read request/error steps=], given |e|
68406837
::
6841-
1. [=Reject=] |promise| with |e|.
6838+
1. Call |failureSteps| with |e|.
68426839
1. Perform ! [$ReadableStreamDefaultReaderRead$](|reader|, |readRequest|).
68436840
</div>
68446841

0 commit comments

Comments
 (0)