Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 节点:对异步对象数组运行方法_Node.js_Asynchronous_Parallel Processing - Fatal编程技术网

Node.js 节点:对异步对象数组运行方法

Node.js 节点:对异步对象数组运行方法,node.js,asynchronous,parallel-processing,Node.js,Asynchronous,Parallel Processing,我有一个同质对象数组。我希望能够并行运行每个对象的方法。如果我同步执行此操作,它将看起来像: var objs = [{run:function(){}},{run:function(){}},{run:function(){}}]; for (obj in objs) { obj.run(); } 我曾考虑过使用异步库,但在那里看不到任何有用的东西。您可以先将对象映射到函数,然后使用 如果函数不是异步的,它们仍然会同步运行,因为NodeJS应用程序中只有一个线程。 var asyn

我有一个同质对象数组。我希望能够并行运行每个对象的方法。如果我同步执行此操作,它将看起来像:

var objs = [{run:function(){}},{run:function(){}},{run:function(){}}];

for (obj in objs) {
    obj.run();
}

我曾考虑过使用异步库,但在那里看不到任何有用的东西。

您可以先将对象映射到函数,然后使用


如果函数不是异步的,它们仍然会同步运行,因为NodeJS应用程序中只有一个线程。
var async = require('async')

var objs = [{run:function(){}},{run:function(){}},{run:function(){}}];
var func2call = objs.map(function(x){return x.run})
async.parallel(func2call);