I’m not able to get my asynchronous code working with node.js
Trying both async and step libraries — the code only returns the first function (doesn’t seem to go through the rest). What am I doing wrong?
thanks!
var step = require('step');
step(
function f1(){
console.log('test1');
},
function f2(){
console.log('test2');
},
function finalize(err) {
if (err) { console.log(err);return;}
console.log('done with no problem');
}
);
or THIS:
var async = require('async');
async.series([
function f1(){
console.log('test1');
},
function f2(){
console.log('test2');
},
function finalize(err) {
if (err) { console.log(err);return;}
console.log('done with no problem');
}
]);
Step.js is expecting callbacks for each step. Also the function that is using Step should callback with the result and not return it.
So let’s say you have:
Using Step would work like:
This would get it to proceed through the steps.
Note that I personally prefer async for two reasons: