Re: [whatwg/streams] Editorial: Add a non-promise version of "fully reading" a stream (PR #1250)

@domenic commented on this pull request.

This works surprisingly well! I think we should just be a bit more aggressive.

>  
  1. Let |promise| be [=a new promise=].
- 1. Let |bytes| be an empty [=byte sequence=].
- 1. [=Read-loop=] given |reader|, |bytes|, and |promise|.
- 1. Return |promise|.
+ 1. Let |success steps| given a [=byte sequence=] |data| be to [=resolve=] |promise| with |data|.
+ 1. Let |failure steps| given a JavaScript value |error| be to [=reject=] |promise| with |error|.
+ 1. [=Consume all bytes=] from |reader| given |success steps| and |failure steps|.

I'd like to get rid of "read all bytes as a promise". Nobody should use it, for various reasons (e.g. having to deal with `then` tampering). https://dontcallmedom.github.io/webdex/r.html#read%20all%20bytes%40%40ReadableStreamDefaultReader%40dfn implies it wouldn't be so bad to break some consumers; I think we could fix Fetch ourselves, file issues on the rest, then move on.

>  
  1. Let |promise| be [=a new promise=].
- 1. Let |bytes| be an empty [=byte sequence=].
- 1. [=Read-loop=] given |reader|, |bytes|, and |promise|.
- 1. Return |promise|.
+ 1. Let |success steps| given a [=byte sequence=] |data| be to [=resolve=] |promise| with |data|.
+ 1. Let |failure steps| given a JavaScript value |error| be to [=reject=] |promise| with |error|.
+ 1. [=Consume all bytes=] from |reader| given |success steps| and |failure steps|.
+
+ <p>To <dfn export for="ReadableStreamDefaultReader">consume all bytes</dfn> from
+ {{ReadableStreamDefaultReader}} |reader|, given |success steps|, which is an algorithm accepting a

successSteps and failureSteps, per more modern style, here and below.

>  
   1. Let |readRequest| be a new [=read request=] with the following [=struct/items=]:
    : [=read request/chunk steps=], given |chunk|
    ::
-    1. If |chunk| is not a {{Uint8Array}} object, [=reject=] |promise| with a {{TypeError}} and
+    1. If |chunk| is not a {{Uint8Array}} object, call |failure steps| with a {{TypeError}} and
        abort these steps.
     1. Append the bytes represented by |chunk| to |bytes|.

While here, it might be best to use https://webidl.spec.whatwg.org/#dfn-get-buffer-source-copy to more rigorously convert |chunk| to a byte sequence.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/pull/1250#pullrequestreview-1214714592
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/streams/pull/1250/review/1214714592@github.com>

Received on Tuesday, 13 December 2022 04:55:02 UTC