I'm going mad trying to figure out what I am doing wrong with this synchronous iterator in node.js, using async:
async.each(ids, function(id,next) {
console.log(id);
tokens.addID(id,function (id_uuid) {
console.log('Added ID '+id_uuid);
next();
});
});
The problem is that the inner call back is not being waited on before the next iteration occurs. But that makes no sense. I've wasted hours, very grateful for any help.
Your problem is a very simple misunderstanding of the meanings of the async function names. async.each executes them all in parallel. You want async.series to execute them one at a time, in order.