0

I'm having troubles processing a queue that I've got stored in Redis.

Basically the queue in Redis is a simple array of IDs that I want to step through one by one.

My current code:

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");
});

I use the async library and above the var data represents an array such as:

['232323', '232423', '23232']

I want to loop through the array but one ID at a time. And not move on to the next ID until the previous one has run through all the callbacks.

Is this somehow possible?

Itamar Haber
  • 47,336
  • 7
  • 91
  • 117
Alosyius
  • 8,771
  • 26
  • 76
  • 120
  • possible duplicate of [Idiomatic way to wait for multiple callbacks in Node.js](http://stackoverflow.com/questions/5172244/idiomatic-way-to-wait-for-multiple-callbacks-in-node-js) – Mike Perrenoud Dec 04 '14 at 12:10

1 Answers1

1

You can use async.eachSeries instead of async.forEach.

c.f.: https://github.com/caolan/async#eachSeries

Mehdi
  • 7,204
  • 1
  • 32
  • 44