I\'m currently working on something where I fire out three promises in an array. At the moment it looks something like this
var a = await Promise.all([Promis
OK, I will leave the accepted answer as is. But I altered it a little bit for my needs as I thought this one is a little easier to read and understand
const firstTrue = Promises => {
return new Promise((resolve, reject) => {
// map each promise. if one resolves to true resolve the returned promise immidately with true
Promises.map(p => {
p.then(result => {
if(result === true){
resolve(true);
return;
}
});
});
// If all promises are resolved and none of it resolved as true, resolve the returned promise with false
Promise.all(Promises).then(() => {
resolve(Promises.indexOf(true) !== -1);
});
});
}