async.series inside an asynchronous grunt task
I have a grunt tasks which runs asynchronously (using this.async) as I have asynchronous functions in the code. I also want few tasks to run in series so I am using async.series from async npm module. Problem is that when I reach the last callback of async.series ie function(err, result), I call a done() to inform that the asynchronous grunt task has been successfully completed, it fails sometimes and passes sometimes. I cannot seem to understand it. Here is the code:
grunt.registerTask('aggCompJSON', function(){
var done = this.async();
var resultFile = {}; // final JSON object
var groupJSON = {}; // groups JSON object
async.series([
function(callback){
// get Application Configuration
__getAppConfig(grunt, callback);
},
function(callback){
// generate Component_map
__genCompMap(grunt, callback);
}
], function (err, result){
done();
}
);
I get the following error:
Fatal error: ENOENT, open 'logs/app.log'
and also sometimes a success. Any input is appreciated. Thanks
PS None of the functions return error. The err object in the last callback is always null .
Thanks for your help @RodrigoMedeiros. Yes you were right, I was trying to require a module in one of the functions and it was behaving unexpectedly. The fix is to just check what statements might cause errors because of asynchronous execution of grunt task. In my case I removed those statements, they were unnecessary.
链接地址: http://www.djcxy.com/p/55486.html