【发布时间】:2016-01-30 22:51:50
【问题描述】:
我正在尝试从通过异步系列运行的任务列表中获取进度
module.exports = update;
function update(){
// Require Deps
var async = require('async');
var progress = require('progress);
var tasks = [task1,task2,task3];
// Create the progress bar using the list of tasks
// as the length of the bar
var bar = new progress(':current/:total [:bar] :task', {
total: tasks.length
});
//Run async series using the array of tasks
async.series(tasks,function(err,result){
// Do something with the results or errors
})
};
var task1 = function(callback){
callback();
};
var task2 = function(callback){
callback();
}
这是我的代码的一个非常简单的版本。
问题
我如何将栏传递给每个函数或“通过”函数和回调到我能够使用的每个任务成功时
bar.tick({'task': tasks[bar.curr]});
我尝试的一切都没有定义 bar,所以尝试使用回调函数(callback,bar)将 bar 传递给函数,然后我得到未定义的刻度
我是 nodeJs 和 js 的新手,所以请温柔
注意 我试图实现的是完成一个在进度条中显示当前任务的功能列表 我已经阅读了文档并查看了有关进度和异步的示例,但仍然无法确定它的正面或反面
我是接近还是有更好的方法
【问题讨论】:
-
你问了一个问题,为什么不投票或接受任何答案?
标签: javascript node.js asynchronous progress