How to call a second function after the execution of first

I have a function f1(valueOfData) executing which I can pull data from an external data source. Also, I have another function f2() which has an if loop and validates that the value has been pulled before calling a third function.
Having tried lots, I am stuck in a situation where in the second function(data Validation function) is getting called before the execution of f1(valueOfData) is complete and the data is pulled(takes a couple of minutes).

I understand that Javascript is event driven and hence tried using the second function(validation function) as a call back but however, I am still unable to achieve it. Also, I am unable to use the window.setTimeOut(millis) as I need to calculate the exact time taken to retrieve the data from the database (using

function call(){

function a(callBack){

Can somebody please help me suggest how to wait for the first function to entirely complete before executing the second.

15 thoughts on “How to call a second function after the execution of first”

Leave a Comment