3 ms·
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 Promis
by remram 4y ago
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.
- 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.