【发布时间】:2017-03-09 14:07:53
【问题描述】:
守则
我尝试了这个包https://www.npmjs.com/package/async 来实现串行和并行处理。
对于小型情况,它可以正常工作,但是当我尝试运行它时,我得到了一个意外的行为:
async.series([
function(callback){
console.log('one');
callback();
},
function(callback){
console.log('two');
async.parallel([
function(callback){
console.log('two-one');
callback();
},
function(callback){
async.series([
function (callback){
console.log('two-two-one');
callback();
},
function (callback){
console.log('two-two-two');
callback();
}
]);
}
], callback);
},
function(callback){
console.log('three');
callback();
}
]);
预期结果
代码应连续打印one、two、two-one 和three。但是,在打印two-one 之后,我想并行打印two-two-one 和two-two-two。
预期的结果是:
one
two
two-one
two-two-one
two-two-two
three
或
one
two
two-one
two-two-two
two-two-one
three
真正的结果
很遗憾,three 永远不会被打印出来。
one
two
two-one
two-two-one
two-two-two
问题
我的代码/理解有问题吗?
谢谢。
【问题讨论】: