I have an async function like the one below. Note that the timeout function is just symbolic of other code that runs in an async way. I want the code to wait till each of the series block is done before returning to the final function.
var async = require('async')
var param1 = 'foobar'
function withParams(param1, callback) {
console.log('withParams function called')
console.log(param1)
callback()
}
function withoutParams(callback) {
if(true){
console.log("withoutParams function called")
setTimeout(function () {
console.log("test") }, 10000);
callback()
}
else{
console.log('This part will never run')
callback()
}
}
async.series([
function(callback) {
withParams(param1, callback)
},
withoutParams
], function(err) {
console.log('all functions complete')
})
The output is
withParams function called
foobar
withoutParams function called
all functions complete
test
I want the output to be
withParams function called
foobar
withoutParams function called
test
all functions complete
Is there any other async version that waits for the final block to finish before calling the ending function(err){... part ? I am learning nodejs.