The following code is asynchronous.
async function test_function() {
await (()=> {
for(let i = 0; i < 10000000000; i+=1) {
}
})();
console.log('hello 2');
}
test_function();
console.log('hello 1');
Output:
hello 1
hello 2
The function runs asynchronously and so we see hello 1
outputted before hello 2
. However, both outputs are printed on the console at the same time rather than hello 2
being printed out a short while after hello 1
. The program should execute code written directly after a call to an asynchronous function but that isn’t happening in this case. Why isn’t there a notable pause between the two logs?