启动脚本app.js如下:
#!/usr/bin/env nodesetTimeout(function(){ console.log('I execute first.'); setTimeout(function(){ console.log('I execute next.');setTimeout(function(){ console.log('I execute last.'); },100); },500);},1000);/*使用Nimble流程控制工具实现异步任务顺序执行。安装Nimble,npm install nimble*/var flow = require('nimble');/*给Nimble一个函数数组,让它一个接一个地执行,尽管这种用流程控制实现的版本代码更多,但通常可读性和可维护性更强。*/flow.series([ function (callback){ setTimeout(function(){ console.log('I execute first.'); callback(); },1000); }, function (callback){ setTimeout(function(){ console.log('I execute next.'); callback(); },500); }, function (callback){ setTimeout(function(){ console.log('I execute last.'); callback(); },100); }]);
新闻热点
疑难解答