0

我有一个功能是-:

function generateAndEmitSessionizedEvents(workflowIdVsClientId, workflowIdVsEvents, clientVsIdVsDoc, esWriteFailedWorkflowIds) {
    return _generateSessionizedEvents(workflowIdVsClientId, workflowIdVsEvents, clientVsIdVsDoc, esWriteFailedWorkflowIds)
        .then(function (messageInfo) {
            return new Promise((resolve, reject) => {
                preValidateUtil.preValidateNullCheck(messageInfo, "vo",  function (messageInfo, err) {
                    if(err) {
                        logger.error("Failed to send slack notification" , err);
                    }
                    return resolve(messageInfo);
                });
            })
    } 

我已经通过了promise preValidateNullCheck 函数,它是-:

function notifySlack(faultyEventsList, callback) {
    var text = `The data for faulty event is : ${faultyEventsList}`;
    slackHelper.slack.sendNotification(text, function (err) {
        if (err) {
            logger.error("ERROR Failed to send the slack notification" + err);
            return callback(err);
        }
    })
}


function preValidateNullCheck(messagesInfo, stream, callback) {
    var faultyEventsList = [];
    var validEventsList = [];
    _.each(messagesInfo, function (messageInfo) {
        var event = messageInfo.message.event_type;
        findSchemaForEvent(event, messageInfo, stream, faultyEventsList, validEventsList);
    });
    notifySlack(faultyEventsList);
    return validEventsList;
}

在 notifyslack 函数中,我已经处理了错误,但仍然必须处理成功回调,不明白该怎么做。

请注意 -:preValidateNullCheck 函数不正确,我不知道天气我也应该在参数或 notifySlack 函数中传递回调。

我不明白如何处理回调,notifySlack 必须在 preValidateNullCheck 函数中发生所有事情之后发生。

我是新手,寻求帮助!

4

0 回答 0