4 ms·
Not sure what `Promise.race(Promise.all(promises), loop());` is supposed to be doing. Promise.race only takes one arg, no? Also not sure what partialUpdate is s
by lhorie 4y ago
Not sure what `Promise.race(Promise.all(promises), loop());` is supposed to be doing. Promise.race only takes one arg, no? Also not sure what partialUpdate is supposed to be doing. Is that assuming some React-like diff reconciliation?
Personally, I'd go with something like this:
async function showChapters(chapterURLs) {
return Promise.all(
chapterURLs
.map((url) => fetch(url).then(r => r.json()))
.map((p, i) => p.then(data => appendChapter(data, i), e => displayError(e, i)))
);
}
With this, you can control exactly where and how list items are rendered, regardless of order of promise resolution, and things are rendered as soon as they are available, instead of getting stuck behind slow requests.