As far as I know, there are two options about promise:
promise.all()
promise.race()
Ok, I know what promise.all()<
Let's take an sample workaround of Promise.race
like below.
const race = (promises) => {
return new Promise((resolve, reject) => {
return promises.forEach(f => f.then(resolve).catch(reject));
})
};
You can see race
function executes all promises, but whomever finishes first will resolve/reject with wrapper Promise
.