如何获取async函数中断的情况?

  let doActions = async (actions) => {
    let ret = null;
    try {
      for(let action of actions) {

        ret = await new Promise((resolve, reject) => {
          let result = action(ret);
          if(typeof result == void 0 || result == false) reject();
          resolve(result);
        });
      }
    } catch(e) {
      console.log(e);
    }
    return ret;
  }
  

其中的action可能会返回一个promise,当这个promise reject的时候,如何获取到这个状态?

阅读 3.6k
1 个回答

resolve 一个 promise 会进入正常的 promise 流程,不用处理 catch 里可以收到

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题