const testAsync = function (name) {
return new Promise((resolve, reject) => {
console.log(name)
resolve(name);
})
}
async function asynFunc () {
let result = ''
result += await testAsync('a')
result += await testAsync('b')
result += await testAsync('c')
}
function test(){
console.log('start')
asynFunc();
console.log('end')
}
test()
the output is:
> "start"
> "a"
> "end"
> "b"
> "c"
but what I'm expecting is
> "start"
> "a"
> "b"
> "c"
> "end"
What cause the result to be Out-of-Sequence? What's more, I was expecting the program to end when it prints 'end', but apparently not.