Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

nodejs 如何同步执行某些模块函数?

我有几个模块,需要这几个模块同步执行,现在时异步执行。整个流程的功能为解压文件并重命名解压后的文件。以下为示例代码,需要注意的是代码的结构不能改变。谢谢大家的帮助!

var mods = [];//模块集合
mods['unzip'] = require('unzip');//解压模块
mods['rename'] = require('rename');//重命名模块

var tasks = ['unzip', 'rename']; //任务执行顺序

var options = {};//传递给模块的参数
tasks.map(function (task) {
    //运行指定模块
    mods[task](options);
});

我尝试过 q, Step, async.series 等,均无法解决我的问题,请 nodejs 大神们给个好的方案。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

最终采用了 node-queuer


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...