Didn't know how else to put this.
Say I have a JavaScript method that makes some AJAX calls:
function makeAJAXCalls()
{
// who knows how long this will take
}
And I don't want the next function to execute until all the AJAX calls are complete. I also don't want to put the next function call into the success callback for the AJAX call.
Is there a way I can like chain these, so the next function doesn't get called until makeAJAXCalls()
is done everything it needs to do?
Answer
var queueCount =0;
function makeAjaxCalls()
{
queueCount+=7; // or however many calls you need to make.
// make your ajax calls. onSuccess (or failure), call checkQueue();
}
function checkQueue()
{
queueCount--;
if (queueCount <=0)
{
doNext();
}
}
This leaves the calls asynchronous, which may be the intent here.
No comments:
Post a Comment