Hi, you can solve the problem with
gate(https://github.com/nakamura-to/gate) and
parray(https://github.com/nakamura-to/parray). Thanks.
var gate = require('gate');
var parray = require('parray');
exports.get_list = function ( cb) {
rclient.smembers("list", function(err, members) {
var latch = gate.latch();
parray.forEach(members, function(member){
console.log(member)
rclient.hgetall(member, latch(1));
}, function () {
latch.await(function (err, results) {
results.forEach(console.log);
cb(null, 'lst');
});
});
});
}
2012/3/20 Angelo Chen <[email protected]>:
> the all in 'hgetall' actually means getting all the properties of that
> member, so for every member it reads the data in, trying out your
> modification, the cb(null, 'lst') was called multiple times.
>
> this is quite a interesting question:
>
> members.forEach(function(member) {
>
> })
>
> cb(null, 'lst‘)
>
> 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?
>
> the real use case is, I got a list, then I'd use the list to retrieve
> the details and check if that details is applicable to certain
> situation, once all check is done, cb(null, 'lst') is called.
>
> any solution to this?
>
>
>
> On Mar 20, 6:20 pm, Oliver Leics <[email protected]> wrote:
>> The "all" in "hgetall" makes me think it gives me a list.
>> Maybe not what you did expect, because I assumed that rclient.hgetall
>> gives all items to the callback, not only one item.
>>
>> 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)
>> rclient.hgetall(member, function(err, items) {
>> if(err) { return cb(err); }
>> console.log(items)
>> cb(null, 'lst');
>> })
>> })
>> })
>>
>>
>>
>>
>>
>>
>>
>> }
>
> --
> 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
--
Toshihiro Nakamura
--
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