节点异步不执行回调

node-async doesn't execute callback

代码

我试过这个包 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();
    }
]);

预期结果

代码应依次打印 onetwotwo-onethree。但是,在打印two-one之后,我想并行打印two-two-onetwo-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

问题

我的code/understanding有问题吗?

谢谢。

异步系列将最后一个参数作为函数来获取最终结果。

请将并行回调作为异步系列的第二个参数传递。

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);// pass parallel callback to trace the outcome 
            }
        ], callback);
    },
    function(callback){
        console.log('three');
        callback();
    }
],console.log);// use console.lg to get the final outcome of series