gpt4 book ai didi

javascript - 如何在 async.eachSeries 回调函数中调用回调函数

转载 作者:太空宇宙 更新时间:2023-11-03 22:28:16 25 4
gpt4 key购买 nike

我尝试在 eachSeries 完成后调用回调函数,但它根本不起作用。它不会打印调用时应该打印的 2 ,但它会在调用第一个函数后打印 4 。有什么想法吗?谢谢!

async.waterfall([
function(callback) {
console.log("1");
let eroJson = [];
rp(optForReddit).then(function(redditJSON) {
let posts = redditJSON.data.children;
async.eachSeries(posts, function(item, callback) {
if (isVideo(item.data.url)) {
eroJson.push(getAlbumId(item.data.url));
}
callback(); // callback function after eachSeries
}, function() {
callback(eroJson); // call next callback
});
})
},
function(redditJSON, callback) {
console.log("2");
callback() // call another function
}
)],
function(){
console.log("Last one");
}

);

最佳答案

更改回调名称。看来您正在覆盖回调名称

    async.waterfall([
function(waterfallCallback) {
console.log("1");
let eroJson = [];
rp(optForReddit).then(function(redditJSON) {
let posts = redditJSON.data.children;
async.eachSeries(posts, function(item, callback) {
if (isVideo(item.data.url)) {
eroJson.push(getAlbumId(item.data.url));
}
callback(); // callback function after eachSeries
}, function() {
waterfallCallback(eroJson); // call next callback
});
})
},
function(redditJSON, waterfallCallback) {
console.log("2");
waterfallCallback();
}
)], function(){
console.log("Done executing all waterfall functions");
});

关于javascript - 如何在 async.eachSeries 回调函数中调用回调函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42185846/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com