mbacvanski mbacvanski - 9 months ago 58
Node.js Question

Node.js Get First Resolved Promise

If I have two promises A and B, only one of which will succeed, how can I get whichever one resolves successfully? I'm looking for something similar to

, but which will return only the first promise that resolves. I'm using promises from ES6.


I would handle this by using Promise.race, but have some code to ignore the errors. Untested but try something like this...

  promiseA.catch((e) => {}),
  promiseB.catch((e) => {})

Note that you might have to give some thought to how you handle cases where they all error out.