Hacker News new | past | comments | ask | show | jobs | submit login

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.



Does 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.


I think that it works because when loop() rejects, Promise.all() rejects too so it doesn't matter who wins.


I 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: