Promise.all([
является разрешением асинхронным, поэтому // this continues to get executed even after the return staement
всегда будет выполняться перед выполнением кода в then
.
Вы должны использовать await
/ async
:
async function somefunc() {
try {
var results = await Promise.all([match2, match3, match4, match5]);
if (results.indexOf(false) > -1) {
return;
} else {
// ............
};
} catch (err) {
console.log(err);
}
// code that is executed if return is not done
}
Или вам нужно переместить код // this continues to get executed even after the return staement
в то время, и вы должны return
цепочку Promise сформировать вашу функцию, чтобы, если кто-то вызывает somefunc
, мог дождаться завершения функции:
function somefunc() {
return Promise.all([match2, match3, match4, match5]).then(results => {
console.log(results);
if (results.indexOf(false) > -1) {
return; // has no effect. somefunc() does NOT return.
} else {
// ............
};
// code that is executed if return is not done
}).catch(err => {
console.log(err);
});
}