Answer the question
In order to leave comments, you need to log in
Do I understand NodeJS async execution order correctly?
Let's say we have a code:
console.log('start');
async.parallel([
function () {
App.loadSettings();
},
function () {
App.loadData();
},
function () {
App.loadData2();
},
]);
console.log('end');
Answer the question
In order to leave comments, you need to log in
Не правильно понимаете. Если функции loadSettings и другие асинхронные, а они конечно асинхронные по своему смыслу, ведь это внешние запросы из базы или с веника, то писать нужно примерно так:
async.parallel([
function (callback) {
App.loadSettings(callback);
},
function (callback) {
App.loadData(callback);
},
function(callback) {
App.loadData2(callback);
},
]);
Your code should look like this:
console.log('start');
async.parallel([
function (callback) {
App.loadSettings(callback);
},
function (callback) {
App.loadData(callback);
},
function(callback) {
App.loadData2(callback);
}
], function(err, results) {
console.log('end', err ? err : results);
});
console.log('start');
async.parallel([
async.apply(App.loadSettings),
async.apply(App.loadData),
async.apply(App.loadData2)
], function(err, results) {
console.log('end', err ? err : results);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question