When I run this script, the output is different from what I expect: 1 through 4. Why is that?
const delay2 = async ( ms: number) => setTimeout( () => {
console.log( '2 - timeout')
}, ms);
const mainAsync2 = async () => {
console.log( '1 - before');
await delay2( 2000);
console.log( '3 - after');
}
mainAsync2()
.then( res => console.log( '4 - done'));
The output is:
1 - before 3 - after 4 - done 2 - timeout