4 ms·
Here is a way with a Generator (the chapterGenerator). Only writing this because I've seen a lot of comments lamenting lack of "streams" async function sho
by clarkdale 4y ago
Here is a way with a Generator (the chapterGenerator). Only writing this because I've seen a lot of comments lamenting lack of "streams"
async function showChapters(chapterURLs) {
const chapterGenerator = function*() {
for(const url of chapterURLs) {
yield fetch(url).then(response => response.json());
}
};
for (const chapter of chapterGenerator()) {
try {
appendChapter(await chapter));
} catch (error) {
handleChapterErrorGracefully(error);
}
}
}