title: How to run angularjs ajax request in loop but with delay?
body: <p>I need to run 20-200 ajax requests in loop but to do not hurt <code>google.maps.Geocoder</code> I want to set delay 10 sec between each call. However <code>ajax</code> request is asynchronous therefore I call next <code>ajax</code> request on response succeeded of previous one.  If I get response too quick, the delay should take place.</p>
  
  <p>Here is a code I wrote so far:</p>
  
  <pre><code> ...
   $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 () {
                  // do something with response
  
                 if($scope.taskCurr &lt;= $scope.taskCount){
                   $scope.taskCurr++;
                   return geoTaskLoopAsync();
                 }
  
                  return;
              });
          });
  </code></pre>
  
  <p>So what next?</p>
  
  <p>can I add something like:</p>
  
  <pre><code> stop = $timeout(function() { 
           if($scope.taskCurr &lt;= $scope.taskCount){               
              geoTaskLoopAsync();
          } else {
              $timeout.cancel(stop);
          }                
      }, 10000);
  </code></pre>
  
  <p>or have I other way?</p>
  
  <p>Thank you,</p>