相关疑难解决方法(0)

然后在之前和之后放置捕获物

我无法理解将.catchBEFORE和AFTER放在嵌套的promise中之间的区别.

备选方案1:

test1Async(10).then((res) => {
  return test2Async(22)
    .then((res) => {
      return test3Async(100);
    }).catch((err) => {
      throw "ERROR AFTER THEN";
    });
}).then((res) => {
  console.log(res);
}).catch((err) => {
  console.log(err);
});
Run Code Online (Sandbox Code Playgroud)

备选方案2:

test1Async(10).then((res) => {
   return test2Async(22)
     .catch((err) => {
        throw "ERROR BEFORE THEN";
      })
      .then((res) => {
        return test3Async(100);
      });
  }).then((res) => {
    console.log(res);
  }).catch((err) => {
    console.log(err);
  });
Run Code Online (Sandbox Code Playgroud)

每个函数的行为如下,如果number为<0test2则test1失败,如果number为,则test1失败,如果number为number则> 10test3失败100.在这种情况下,test2只是失败了.

我尝试运行并使test2Async失败,BEFORE和AFTER之后的行为方式相同,并且没有执行test3Async.有人可以向我解释将捕捞放在不同地方的主要区别吗?

在每个函数中我console.log('Running test X')都要检查它是否被执行.

这个问题出现是因为我发布的上一个帖子如何将嵌套回调转换为promise?.我认为这是一个不同的问题,值得发布另一个主题.

javascript node.js promise bluebird

81
推荐指数
2
解决办法
2万
查看次数

标签 统计

bluebird ×1

javascript ×1

node.js ×1

promise ×1