小编wil*_*msi的帖子

我可以在异步函数的try/catch块中使用多个'await'吗?

async asyncfunction(){
  try{
    await method1();
    await method2();
  }
  catch(error){
    console.log(error);
  }
}
Run Code Online (Sandbox Code Playgroud)

给定method1()和method2()是异步函数.每个await方法都应该有一个try/catch块吗?是否有更清晰的方式来写这个?我试图避免'.then'和'.catch'链接.

javascript asynchronous

6
推荐指数
2
解决办法
3968
查看次数

标签 统计

asynchronous ×1

javascript ×1