Algorithm for setting a handler for when multiple ajax request returns in JS
<p>I am writing a program where I need to put out n number of Ajax requests, I want to write a handler to be executed when all of them returns.</p>

<p>What is a good way to do this?</p>

<p>*my initial thought is to create a counter that is incremented when you create a request and decremented when the request returns. When you are at 0, do your handler. However, this creates a race condition where if you don't create your requests fast enough, your previous requests might return first and decrement your counter to 0 and execute the handler. Is there a better way to do this?</p>
