Re: [whatwg/streams] Fix readable byte stream example (#1080)

@ricea commented on this pull request.



> -   .catch(e => console.error("Something went wrong!", e));
-
- function readInto(buffer, offset = 0) {
-   if (offset === buffer.byteLength) {
-     return Promise.resolve(buffer);
-   }
+ const buffer = await readInto(startingAB);
+ console.log("The first 1024 bytes: ", buffer);
+
+ async function readInto(buffer) {
+   let offset = 0;
+   let view;
+   let done;
+
+   do {
+     ({value: view, done} =

Good! I hadn't noticed that we were no longer using `view` and `done` outside the loop.

> -   .then(buffer => console.log("The first 1024 bytes:", buffer))
-   .catch(e => console.error("Something went wrong!", e));
-
- function readInto(buffer, offset = 0) {
-   if (offset === buffer.byteLength) {
-     return Promise.resolve(buffer);
-   }
+ const buffer = await readInto(startingAB);
+ console.log("The first 1024 bytes: ", buffer);
+
+ async function readInto(buffer) {
+   let offset = 0;
+   let view;
+   let done;
+
+   do {

Agree. A regular `while` loop is easier to understand.

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

Received on Tuesday, 27 October 2020 15:58:05 UTC