mbacvanski mbacvanski - 5 months ago 36
Javascript Question

Get first fulfilled promise

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

, but which will return only the first promise that fulfills. 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.