I am facing an issue while using async-await function in javascript.Let's have a look my code first.
function take() {
setTimeout(() => {
console.log('take order');
}, 4000);
}
function complete() {
setTimeout(() => {
console.log('complete order');
}, 20);
}
async function processOrder() {
let a = await take();
let b = await complete();
}
processOrder();
In the code above,I used await to control the order of the tasks.But it didn'twork.The complete function exicuted before the taks function.But I used await to wait in the task function to exicute and then the complete function exicution.
This is not a real life issue.I wonder what is going on here.Can anyone please explain it to me?