Understanding Node.JS async.parallel

前端 未结 1 1645
闹比i
闹比i 2020-12-13 04:37

I need to request data from two web servers. The tasks are independent; therefore, I am using aync.parallel. Now I am only writing \'abc\', \'xyz\', and \'Done\' to the body

相关标签:
1条回答
  • 2020-12-13 05:22

    If you want to be absolutely certain in the order in which the results are printed, you should pass your data (abc\n and xyz\n) through the callbacks (first parameter is the error) and handle/write them in the final async.parallel callback's results argument.

    async.parallel({
        one: function(callback) {
            callback(null, 'abc\n');
        },
        two: function(callback) {
            callback(null, 'xyz\n');
        }
    }, function(err, results) {
        // results now equals to: results.one: 'abc\n', results.two: 'xyz\n'
    });
    
    0 讨论(0)
提交回复
热议问题