0

I have some asynchronous API calls. I need to do some work when the calls have finished. I have all my API calls inside a function like that :

function startProcess() {
   asyncCall();
}

How do i create a callback function for the startProcess() function , so that i could run some code when the asyncCall has finished?

2
  • 2
    The only clean solutions suppose that asyncCall itself can accept a callback or post an even somehow when it finishes. Commented Jul 31, 2013 at 9:26
  • asyncCall has a callback function. The problem is that through the callback function asyncCall will be called a couple more times with different parameters. So i cant be sure through that callback function when it will finish. If you have time to see what i mean check this: stackoverflow.com/questions/17965124/… . This is my problem exactly. Commented Jul 31, 2013 at 9:28

1 Answer 1

1

Try the jquery $.when jQuery API

Something like this:

$.when( startProcess ).done(
    function() { /* do something */ }
);
Sign up to request clarification or add additional context in comments.

3 Comments

hmm i get this error : Uncaught SyntaxError: Unexpected token (
I edited the answer, it seems that this could be the correct sintax, let me know.
is correct but if the call is asynchronous , that doesnt mean that it will wait for that call to finish. Thats what i am trying to accomplish. Thank you very much though

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.