目前为止: 对异步回调地狱的一个终极的处理方法
// async : 这是一个异步的函数
// 把异步的处理机制,写成接近同步的处理机制,以增加代码的可读性,降低版本迭代的难度
<script>
async function fn(){
try{
let n1 = await new Promise((resolve)=>{
setTimeout(() => {
resolve();
console.log(1);
},1000);
});
let n2 = await new Promise((resolve)=>{
setTimeout(() => {
resolve();
console.log(2);
},1000);
});
let n3 = await new Promise((resolve)=>{
setTimeout(() => {
resolve();
console.log(3);
},1000);
});
}catch(err){
console.log(err);
}
}
fn();
</script>