承诺'拒绝和解决回调是否可能同时被调用?

时间:2022-08-23 11:46:06

My code looks like this,

我的代码看起来像这样,

export function handleLogin(window,userData){
    return (dispatch) => {
        Meteor.call('checkUserLogin',userData,
            (error,result)=>{
                if(result.isLogin && !error) {             
                    Meteor.call('SOMECALL',SOMEDATA (e,r)=>{
                    if(!e) {                           
                            async function getData(){ return await getAdminUgData();}
                            getData()
                            .then((d)=>{console.log('resolve!!');})
                            .catch((e)=>{console.log('!!reject'); });
                        }
        });
        });

    }; }

the getAdminUgData is,

getAdminUgData是,

export function getAdminUgData(){
return new Promise((resolve, reject) => {
    Meteor.call('adminGetUserGroupData', (e,r)=>{
        if(e) reject(new Error('error'));
        else resolve(r);        

    });
});}

I am supposed to print out 'resolve' only because the resolve(r); is confirmed being called in getAdminUgData. But the confusing/weird reality is that 'resolve!!' is printed and after that, '!!reject' is also printed. And I completely have no ideas about this. Any suggestions are welcome; thanks.

我应该打印'决心'只因为决心(r);确认在getAdminUgData中被调用。但令人困惑/奇怪的现实是“解决!!”打印后,打印出'!! reject'。我对此完全没有任何想法。欢迎任何建议;谢谢。

1 个解决方案

#1


2  

No, it's absolutely impossible for the same promise to both reject and fulfill - and so it will never happen that both callbacks to .then(…, …) are called. It is however totally possible that both a .then(…) and a .catch(…) callback are called when chained - notice that this doesn't seem to be the case in your example, it seems there's something else going on.

不,绝对不可能同时承诺拒绝和履行 - 所以永远不会发生对.then(......,...)的回调都被调用。然而,链接时调用.then(...)和.catch(...)回调完全有可能 - 请注意,在您的示例中似乎不是这种情况,似乎还有其他事情发生。

#1


2  

No, it's absolutely impossible for the same promise to both reject and fulfill - and so it will never happen that both callbacks to .then(…, …) are called. It is however totally possible that both a .then(…) and a .catch(…) callback are called when chained - notice that this doesn't seem to be the case in your example, it seems there's something else going on.

不,绝对不可能同时承诺拒绝和履行 - 所以永远不会发生对.then(......,...)的回调都被调用。然而,链接时调用.then(...)和.catch(...)回调完全有可能 - 请注意,在您的示例中似乎不是这种情况,似乎还有其他事情发生。