0
我正在推送messages_filtered數組中的數據,但是當我嘗試在回調中將其始終爲空時。我在異步循環中將數據推入了兩次。 retMessages是從messages_filtered創建的,但它的空retMessages總是空的。陣列推送正在填充node.js中的陣列
Service.poll = function(user, callback) {
var messages_filtered = [];
async.forEach(activeAccountsFor(user), function(acct, done) {
graph.setAccessToken(acct.accessToken);
var connections = ['feed', 'links', 'tagged', 'posts', 'notes', 'inbox', 'outbox'];
var args = acct.updated_time ? {since: acct.updated_time - 3000} : {};
args['date_format']= 'U';
User.markAsUpdated(user._id);
User.markAccountAsUpdated(user._id, acct.userID);
async.forEach(connections, function(connection, next) {
graph.setOptions(options).get('me/' + connection, args,
function(err, feed) {
if (err) {
winston.log('error', 'Error in connection ');
return done();
}
async.forEach(feed.data, function(datum, onward) {
profanity_service.analyzeFeedItem(datum, function(err, result) {
if(!_.isUndefined(datum.comments)){
if(!_.isUndefined(datum.comments.data) && !_.isEmpty(datum.comments.data)){
_.each(datum.comments.data, function(data){
if(moment(data.created_time).unix() >= user.updated_time){
profanity_service.analyzeFeedItem(data, function(err, result) {
if(!err && result){
if (result.isProfane){
messages_filtered.push(result);
}
}
});
}
});
}
}
if(!err && result){
if (result.isProfane) {
messages_filtered.push(result);
}
}
onward(err);
});
}, next);
});
}, done);
}, function(err) {
console.log('messages_filtered.length ' + messages_filtered.length);
if (messages_filtered.length > 0) {
var retMessages = [];
_.each(messages_filtered, function(message) {
if (!hasMessage(retMessages, message)) {
retMessages.push(message)
Message.flag(user._id, message);
}
});
user.notify(retMessages);
}
callback(err);
});
};
不錯的聖誕樹你在那裏:P – PeeHaa