Nodejs:非同步流程控制(下)
阿新 • • 發佈:2018-12-12
//非同步操作,序列有關聯(瀑布流模式) //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("主程序執行完畢");