1

My requirement is very simple.

 subscribePresence();
 getValidationData();

getValidationData() must be called only when subscribePresence(); finishes its execution. is there any way of doing it ?

5
  • What does the first function execute? Commented May 5, 2016 at 5:02
  • It seems like you know what a callback is, so what have you tried? Commented May 5, 2016 at 5:09
  • 1
    That's exactly how Javascript works. The code you have supplied will guarantee that subscribePresence(); finishes executing before getValidationData(); is called. JavaScript executes code in order. Whether or not subscribePresence(); starts some other asynchronous task has nothing to do with it finishing its execution. Commented May 5, 2016 at 5:09
  • Possible duplicate of Create a custom callback in JavaScript Commented May 5, 2016 at 5:14
  • 1
    Show us the code for subscribePresence() so we can see whether it is asynchronous or not and, if so, how to know when it is done with its work. Commented May 5, 2016 at 5:18

1 Answer 1

1

Pass getValidationData(); as callback function into first function.

Ex:

function subscribePresence(callback){
  //do your stuffs
  callback();
}

Now call your subscribePresence() as below

subscribePresence(getValidationData);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.