-
-
Save jakearchibald/0b37865637daf884943cf88c2cba1376 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function getResponseSize(url) { | |
const response = await fetch(url); | |
let total = 0; | |
// Here comes the new bit… | |
for await (const value of response) { | |
total += value.length; | |
console.log('Received chunk', value); | |
} | |
return total; | |
} |
@stryju with:
for (const item of collection)
…collection[Symbol.iterator]
is called to get an iterator for collection
. With:
for await (const item of collection)
…collection[Symbol.asyncIterator]
is called to get an iterator that returns promises.
I get TypeError: response is not async iterable
.
response is a Promise
and is not iterable, an array of them would be iterable however.
I get
TypeError: response is not async iterable
.
i get the same error
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
shouldn't it be
just trying to grasp how would it know about what is "awaitable" in this
for..of