我正在尝试串联调用 3 个函数,但是最后一个函数也有一个 for 循环,我有下面的代码,但是当我运行它时,我得到了callback()
调用之后的错误calanderItems.push()
:
if (called) throw new Error("Callback was already called.");
async.series([
function(callback){
//some database query
callback();
},
function(callback){
//other database query
callback();
},
function(callback){
var google_calendar = new gcal.GoogleCalendar(req.user.accessToken);
var calenderItems = [];
google_calendar.calendarList.list(function(err, calendarList) {
async.each(calendarList.items, function (item, callback){
google_calendar.events.list(item.id, function(err, calenderItem) {
calenderItems.push(calenderItem);
callback();
});
},function(err){
for (var element in prettyArray){
calenderitems.push(prettyArray[element])
}
console.log(calenderitems);
});
});
}
]);