const Producer_code = () => {
console.log(3)
console.log(4)
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(0); // Resolve the promise once the timeout is complete
}, 2000);
});
};
const Consumer_code = async () => {
const zero = await Producer_code(); // Wait for Producer_code to complete
console.log(zero);
console.log(1);
console.log(2);
};
Producer_code()
Consumer_code();
Expected Ans: 3,4,0,1,2
Actual Ans: 3,4,3,4,0,1,2
Unable to understand why is it so
Ps: New to the asynchronous nature of JS