【发布时间】:2021-12-08 11:52:39
【问题描述】:
当我运行这个脚本时,输出与我预期的不同:1 到 4。这是为什么?
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'));
输出是:
1 - before 3 - after 4 - done 2 - timeout
【问题讨论】: