I have looked over this post: setTimeout in Node.js loop in hopes that it would solve my issue, and in a way it has. However, I am encountering a new issue that I am unable to resolve on my own.
I have been trying to fix this issue for the past couple of hours, but I have had no luck. Here is what I have:
The function that needs to be called in the timeout function:
function searchLDAP(i, app, userUID){
app.process_args(userUID[i]);
}
This is the portion of the code that is not working properly. The code works for the first iteration (userUID[0]
), however when it tries to recurse, i
becomes undefined
.
function doSetTimeout(i, count, app, userUID) {
if(i == count - 1){ callback(); }
searchLDAP(i, app, userUID);
++i;
setTimeout(doSetTimeout, 2000);
}
I am using node's async module
async.series([
function(callback) {
app.readLines(input, callback); // userUID is and array that
// is returned from this function
},
function() {
var count = userUID.length;
var i = 0;
doSetTimeout(i, count, app, userUID);
}
], function(err) {
console.log('all functions complete');
});
Thank you in advance
-Patrick