08. Async Iteration
async function f() {
for await (const x of createAsyncIterable(["a", "b"])) {
console.log(x);
}
}
// Output:
// a
// basync function example() {
const arrayOfFetchPromises = [fetch("1.txt"), fetch("2.txt"), fetch("3.txt")];
// Regular iterator:
for (const item of arrayOfFetchPromises) {
console.log(item); // Logs a promise
}
// Async iterator:
for await (const item of arrayOfFetchPromises) {
console.log(item); // Logs a response
}
}Last updated