与 promise 一起使用时,异步瀑布不执行下一个回调方法

async waterfall not executing next callback method when used with a promise

本文关键字:布不 执行 下一个 方法 回调 异步 一起 promise      更新时间:2023-09-26
async.waterfall(eventIDs.map(function (eventId) {
            console.log(eventId);
            return function (lastItemResult, nextCallback) {
                if (!nextCallback) {
                    nextCallback = lastItemResult;
                    lastItemResult = null;
                }
                // same execution for each item in the array
                var eventPromise = loadEventsData.loadFormData(eventId, apiList);
                eventPromise.then(function (response) {
                    console.log(response);
                    var itemResult = response;
                    // results carried along from each to the next
                    nextCallback(itemResult, nextCallback);
                });

            }}), function (err, result) {
            // final callback
        });

console.log(eventId)的输出是正确的,它的打印次数与数组中的项目一样多。 但是console.log(response)只打印一次,这意味着回调没有被正确调用?

我修改了,问题得到了解决

nextCallback(null, itemResult);