Promise.props结果未定义

时间:2019-05-03 08:29:46

标签: node.js asynchronous promise

我有以下代码,我希望在第 console.log(result)行出现定义的结果; // G1:未定义G2:未定义 但是所有键都变得不确定

我的呼叫流程像callTest1-> processGroup()-> checkDetails() checkDetails()将返回错误,该错误将被processGroup()捕获,并将错误消息设置为组,然后返回至callTest1()

我确实进行了调试,processGroup()返回了更新的组,但是callTest1()仍然具有未定义的

function callTest1(authorizationHeader, form, customer, callback) {
    let isTeams = form.orderType.serviceTypes.Teams ? true : false;
    if (isTeams) {
    var group = _.pick(form, ['outGroups']);
    var outGroups = _.groupBy(group.outGroups, function (trunk) {
        return group.name;
    });
    Promise.props(_.mapValues(outGroups, processGroup.bind(null, form, customer, authorizationHeader)))
        .then(function (result)  {
            // the values will be collected here.
            console.log(result); //  G1 : undefined G2 : undefined
          });
    } else {
        callback(null, form, customer);
    }
}


function processGroup(form, customer, authorizationHeader, groups, key) {
    console.log('processGroup key ', key);
        async.waterfall([
            async.apply(checkDetails, authorizationHeader, form, customer, group)//,
            //async.apply(callTest3, authorizationHeader, form, group),
        ], function (result) {
                groups = _.map(groups, function (group) {
                    group.groupError = result.groupError;
                    return groups;
                });
                return groups;

        });
}


function checkDetails(authorizationHeader, form, customer, group, callback){
        //some code 
        callback(err);
}

0 个答案:

没有答案