var async = require('async');
function f1() {
setTimeout(function(){ console.log('111');},300);
}
function f2() {
setTimeout(function(){ console.log('222');},100);
}
async.series([f1,f2], function(err, result){
console.log(result);
});
It prints:
111
No 222? Why?
f1()andf2()are expected to complete asynchronously, so they are given a callback to invoke when they are “done”. Try this instead:Edit: regarding the “why”, it’s because
f1()gets invoked immediately, and so your initialsetTimeout()is scheduled as expected. However, since you are never tellingasyncthatf1()is done, it never invokesf2().