I'm trying to do some calculation asynchronously and get the result from the calculation in the callback.
function customWithCallBack(callback) {
//Complex logic calculation that takes time.
callback();
}
function actualCallBack() {
console.log("This is callback called after certain event");
}
console.log("First");
customWithCallBack(actualCallBack);
console.log("Second");
//Required Output
First
Second
This is callback called after certain event.
//Actual Output
First
This is callback called after certain event
Second
How can I achieve the required output? That is first "First is printed". Then, "Second". And at last after the completion of complex logic callback is called to print "This is callback called after certain event". Is it possible to do it for complex calculations except network req and i/o operations?