I want to have a callback called, when a async task is completed. Following is the code for the same:
var async = require("async");
function callMeWhenDone(err, result){
if(err) console.log('Error Occurred');
console.log('Callback called');
console.dir(result);
}
function tasks() {
console.log('Start executing tasks');
var tasks = [];
var result = {};
tasks.push(function(callMeWhenDone) {
console.log('Getting some data');
callMeWhenDone(null, result);
});
tasks.push(function(callMeWhenDone) {
console.log('Second function called');
callMeWhenDone(null, result);
});
async.series(tasks, function(err, result){
console.log('All done');
callMeWhenDone(err, result);
});
}
tasks();
In the code above, callMeWhenDone callback method is not getting called after a async task is completed.
How can i call it within the async task.