> since forEach is a synchronous as you pointed out, cb got called at
> end of the loop, that's what I was expecting, but when every iteration
> also calls an asynchronous callback, that will be different as those
> asynchronous calls in fact happens after the cb(null, 'lst'), how to
> deal with this kind of situation?
Get the definite number of comming items:
exports.get_list = function (cb) {
rclient.smembers("list", function(err, members) {
if(err) { return cb(err) }
if(members.length==0) return cb(null, 'lst');
members.forEach(function(member){
console.log(member)
var pending = rclient.hnumall(member);
if(!pending) cb(null, 'lst')
rclient.hgetall(member, function(err, item) {
if(err) { return cb(err) }
console.log(item)
if(!(--pending)) cb(null, 'lst')
})
})
})
}
Or use an second callback on rclient.hgetall and call it at the end of
iteration:
rclient.hgetall(member, cb, cbDone)
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en