0
我試圖圍繞異步庫包裹我的頭,但我在NodeJs中搖擺不定,而且我無法弄清楚async.parallel。下面的代碼在執行並行任務的行上產生錯誤TypeError: undefined is not a function
。我是否正確,在async.parallel中運行的任務在完成後應該有callback()
? (該功能不相關的部分刪節)NodeJs異步並行:'undefined不是一個函數'
function scrapeTorrents(url, callback) {
request(url, function(err, res, body) {
if(err) {
callback(err, null);
return;
}
var $ = cheerio.load(body);
var results = [];
var asyncTasks = [];
$('span.title').each(function(i, element){
// scrape basic info
var show = {title: info.title, year: info.year};
asyncTasks.push(
getOmdbInfo(show, function (err, res) {
if (res) {
omdbInfo = res;
results.push({
// add basic info and Omdb info
});
}
callback();
})
);
});
async.parallel(asyncTasks, function(){
callback(null, results);
});
});
}