【发布时间】:2014-12-04 12:06:05
【问题描述】:
我在处理存储在 Redis 中的队列时遇到问题。
基本上,Redis 中的队列是一个简单的 ID 数组,我想一个一个地遍历。
我当前的代码:
async.forEach(data, function(n, done) {
redisClient.hgetall("visitor:" + n, function(err, visitor) {
if (visitor != null) {
agentOnlineCheck(visitor['userID'], function(online) {
if (online == true) {
console.log("We are done with this item, move on to the next");
} else {
console.log("We are done with this item, move on to the next");
}
});
} else {
console.log("We are done with this item, move on to the next");
}
});
}, function() {
console.log("I want this to fire when all items in data are finished");
});
我使用async库,上面的var data代表一个数组如:
['232323', '232423', '23232']
我想循环遍历数组,但一次只有一个 ID。在前一个 ID 执行完所有回调之前,不要继续下一个 ID。
这有可能吗?
【问题讨论】:
标签: node.js