我正在使用BRAC模块来执行并行任务。基本上,我有两个不同的文件,dashboard.js和Run.js。
Dashboard.js
module.exports = {
func1 : function(){
console.log(“Funtion one”);
},
func2 : function(){
console.log(“Funtion two”);
}
}
运行.js
var dashboard = require(‘dashboard.js’);
var async = require('async');
async.parallel([dashboard.func1, dashboard.func2],function(err){
if(err)throws err;
console.log(“ All function executed”);
});
我期望func1和func2并行执行,但它抛出了下面的错误。
TypeError: task is not a function
at C:\Users\..\java\realtime-preview\node_modules\async\lib\async.js:718:13
at async.forEachOf.async.eachOf (C:\Users\..\java\realtime-preview\node_modules\async\lib\async.js:233:13)
at _parallel (C:\Users\\java\realtime-preview\node_modules\async\lib\async.js:717:9)
为什么即使dashboard.func1是一个函数,我也不能使用dashboard.func1,dashboard.func2?
2条答案
按热度按时间rqmkfv5c1#
对于Cashc属性,我将使用回调特性。此功能也有利于非阻塞呼叫。
使用您的代码,您可以尝试
文件 Dashboard.js
文件 * 运行.js*
还有一个问题和你的类似:Best way to execute parallel processing in Node.js
此外,错误的具体答案是:TypeError: task is not a function in async js parrallel
pvabu6sv2#
请确保您正在使用的API路径不应该有任何返回。我这样调用API后解决了这个问题.请不要我在当地工作时就面临着这一点
请让我知道如果任何问题。