A
A
artshelom2019-11-12 01:11:06
Node.js
artshelom, 2019-11-12 01:11:06

How to have a sequence of conclusions??

Can't figure out async in nodejs.
I took this example:

function display(data, callback){
    setTimeout(function(){
        callback(null, data);
    }, 0);
}
console.log("Начало работы программы");
display("Обработка данных...", function (err, data){
    if(err) throw err;
    console.log(data);
});
console.log("Завершение работы программы");

How can I make the methods execute sequentially?
For example, if we used the place of display db, how would it be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
abberati, 2019-11-12
@abberati

No way. Synchronous code is executed first, then asynchronous. You can put the completion in a callback, then it will be executed asynchronously after processing the data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question