//异步操作,串行有关联(瀑布流模式)
//npm install async --save-dev
var async = require('async');
function exec() {
async.waterfall(
[
function (done) {
i = 0;
setInterval(function () {
console.log("aaa==" + new Date());
i++;
if (i == 3) {
clearInterval(this);
done(null, 'one完毕');
}
}, 1000);
},
function (preValue, done) {
j = 0;
setInterval(function () {
console.log(preValue + "bbb==" + new Date());
j++;
if (j == 3) {
clearInterval(this);
done(null, preValue + 'two完毕');
}
}, 1000);
}
], function (err, rs) {
console.log(err);
console.log(rs);
}
)
}
exec();
console.log("主进程执行完毕");
Nodejs:异步流程控制(下)
猜你喜欢
转载自blog.csdn.net/u013101178/article/details/84728723
今日推荐
周排行