How do I handle asynchronous calls to make sure they do not overlap?
This is my scenario---
I have a loop and within the loop I make a call to a google API and specify a call back function. My callback function processes the results and writes the output to a table.
However I have noticed that the results being written to the table seem to overlap or get mixed up i.e say I call the API at loop counter = 10, the result for loop counter = 10 may appear in the table beside the value for loop counter = 15.
How do I ensure that my callback function does not overlap? My code is written in javascript.
Also can anyone point me to a good and easy to understand documentation on asynchronous calls?