I have a node application that use some async functions.
How can i do for waiting the asynchronous function to complete before proceeding with the rest of the applic
function operation(callback) {
var a = 0;
var b = 1;
a = a + b;
a = 5;
// may be a heavy db call or http request?
// do not return any data, use callback mechanism
callback(a)
}
operation(function(a /* a is passed using callback */) {
console.log(a); // a is 5
})
async function operation() {
return new Promise(function(resolve, reject) {
var a = 0;
var b = 1;
a = a + b;
a = 5;
// may be a heavy db call or http request?
resolve(a) // successfully fill promise
})
}
async function app() {
var a = await operation() // a is 5
}
app()