javascript - How to run angularjs ajax request in loop but with delay? -
i need run 20-200 ajax requests in loop not hurt google.maps.geocoder want set delay 10 sec between each call. ajax request asynchronous therefore call next ajax request on response succeeded of previous one. if response quick, delay should take place. here code wrote far: ... $scope.addresslist = ....; $scope.taskcount = $scope.addresslist.length; geotaskloopasync(); function geotaskloopasync(){ // on success douncount taskcount var geo = new google.maps.geocoder(); geocoder.geocode( { 'address': address }, function(results, status) { $scope.$apply( function () { // response if($scope.taskcurr <= $scope.taskcount){ $scope.taskcurr++; return geotaskloopasync(); } return; }); }); so next? can add like: stop = $timeout(function() { if($scope.taskcurr <= $scope.taskcount){ ...