Re: [whatwg/streams] ReadableStream should be an async iterable (#778)

I have some code like this. But vscode show some errors (`Type 'Promise<ReadableStreamReadResult<Uint8Array>>' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.`) around `reader.read()`.

```js
    const response = await fetch(`${download_url_prefix}${node_executable_filename}`)
    const contentLength = +(response.headers.get('Content-Length') ?? 0);
    const reader = response.body?.getReader();
    if(!reader) {
      throw new Error(`Failed to get reader from response body`);
    }
    let receivedLength = 0;
    let chunks = []; 
    for await (let {done, value} of reader.read()) {
      chunks.push(value);
      receivedLength += value.length;
      console.log(`Received ${receivedLength} of ${contentLength}`)
    }
```

I have to rewrite the above `for await` to `while`.

```js
    while (true) {
      const { done, value } = await reader.read();
      if (done) {
        break;
      }
      chunks.push(value);
      received_length += value.length;
      console.log(`Received ${receivedLength} of ${contentLength}`)
    }

```

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/778#issuecomment-1893328405
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/streams/issues/778/1893328405@github.com>

Received on Tuesday, 16 January 2024 09:06:18 UTC