I have a Java Script function that takes an undefined time to finish. In a loop I want to wait until the function is finished, then wait a defined time (e.g. 5000 ms) and call the function again. How do I accomplish this in Java Script?
Basically I want this:
call function and wait until it is finished
wait another 5000 seconds
call function and wait until it is finished
wait another 5000 seconds
...
The function itself looks like this:
for every group in list
.ajax(delete group items; get group items; add group items)
The problem I currently have is that in the middle of the loop the function is somehow called again.