Good day, I'm learning async await JavaScript and i just started. How to check if all my promises all done? just little confuse about that part. check my code if i'm doing it right. also i'll be happy if there are explanation. TIA
function resolveAfter2Seconds() {
return new Promise(resolve => {
setTimeout(() => {
resolve('resolved');
}, 2000);
});
}
function resolveAfter5Seconds() {
return new Promise(resolve => {
setTimeout(() => {
resolve('resolved');
}, 5000);
});
}
function resolveAfter7Seconds() {
return new Promise(resolve => {
setTimeout(() => {
resolve('resolved');
}, 7000);
});
}
async function checkIfAllFunctionDone() {
console.time('main')
const result = await [resolveAfter2Seconds(), resolveAfter5Seconds(), resolveAfter7Seconds()];
console.log(result);
console.timeEnd('main')
if(result){
console.log('start saving...')
}
}
checkIfAllFunctionDone();