3 ms·
Like I said I added a solution in the Disqus thread to that blog post... the English summary is that you Promise.race() the Promise.all() with the for-await loo
by crdrost 4y ago
Like I said I added a solution in the Disqus thread to that blog post... the English summary is that you Promise.race() the Promise.all() with the for-await loop.
- remram 4y agoDoes that work? Isn't it possible for the monitor() function to return the result of Promise.all() rather than loop(), since they are racing? return Promise.race(Promise.all(promises), loop()); edit: I guess they are the same in this specific case, but probably wouldn't be in real code, making this function very clever but maybe too rigid.
- scotty79 4y agoI think that it works because when loop() rejects, Promise.all() rejects too so it doesn't matter who wins.
- remram 4y agoI mean in the case where nothing rejects. Say for example the loop was doing `result.push({success: true, value: item})` instead of just `result.push(item)`. Then the value returned from loop() is different from the one returned by Promise.all(promises), and your overall monitor() function might return either.