简体   繁体   English

Node.js async.each不等待迭代

[英]Node.js async.each does not wait to iterate

I'm going mad trying to figure out what I am doing wrong with this synchronous iterator in node.js, using async: 我很生气,试图通过使用async来弄清node.js中的这个同步迭代器在做什么:

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. async.each并行执行它们。 You want async.series to execute them one at a time, in order. 您希望async.series一次一次执行它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM