function getTimeOut1() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve("===5000ms===");
}, 5000);
});
}
function getTimeOut2() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve("===2000ms===");
}, 2000);
});
}
how to achieve this (split execution) effect with async/await:
getTimeOut1().then(res => {
console.log(res);
});
getTimeOut2().then(res => {
console.log(res);
});
- ordinary await will wait for the returned result of a to execute b-> 8000ms +
const a = await getTimeOut1();
const b = await getTimeOut2();
- is in the form of Promise.all ([.p]). Although it is a parallel operation, it waits for the slowest execution before the result is returned. -> 5000ms +
so I didn"t figure out how to use async/await to implement regular parallel callbacks.