Answer the question
In order to leave comments, you need to log in
How to write asynchronous code in conditional statements?
Follow-up to this question ( How to write asynchronous code correctly? ), but without a direct link.
There is a function in which data can be repeatedly modified asynchronously, after which it is passed to callback functions. When should a callback be made?
function(data, callback){
if(data.someCondition1){
doAsyncCode(data, function(err, result){
...
}
}
if(data.someCondition2){
doAsyncCode(data, function(err, result){
...
}
}
// В конце нужен коллбэк
}
Answer the question
In order to leave comments, you need to log in
The easiest way is to use the async module and its waterfall method .
The easiest way is not to suffer and use async / await from ES7, though so far only with a preprocessor, example , your specific case .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question