Since async function is non-blocking, I expected asyncfunc in below code does not block and console.log(a) prints zero.
var a = 0;
const asyncfunc = async () => {
for (let i = 0; i < 1000000000; i++) {}
a = 1;
return 2;
};
const asyncmain = async () => {
a = asyncfunc();
console.log(a);
return true;
};
asyncmain();
But when I executed, all code in asyncfunc ran first and then console log is written. function is blocked at async function first!
expected : 0 actual : Promise { 2 }
I cannot understand this result. help me to understand this result!
ps I ran this code on node.js v10.15.3
await. - VLAZ