承诺然后被拒绝,然后被解决

时间:2019-08-01 20:20:32

标签: javascript promise

我们建立了一个链接的诺言框架类型的东西。它执行异步调用,处理响应的.then()然后解析或拒绝承诺,另一个向承诺中添加.then()的组件,最后在各个组件中使用。

这种情况对我来说毫无意义:

第一个then在诺言上呼叫reject

第二个then调用其reject回调。

第三then调用其resolve回调。

我认为第三个也将调用其reject回调。目标是,如果调用resolve,则所有then都使用各自的resolve回调,如果拒绝,则每个then都使用其reject回调。

TheAJAXCall(){
    return new Promise(function(resolve, reject){
        axios({
            //doesn't matter what is here, just pretend it works
        }).then(function(response){
            reject(response)
        });
    });
}

SetupOurCall(){
    return TheAJAXCall().then(function(){
        console.log("second then resolved"); //ignored as expected
        return response;
    }, function(){
        console.log("second then rejected"); //called as expected
    })
}

MyFunction = function(){
    SetupOurCall().then(function(){
        console.log("How did I get resolved");  //this is resolved?!?!?
    }, function(){
        console.log("I want this to be rejected"); //why not rejected?
    })
}

0 个答案:

没有答案