title: Concurrency in Angularjs
body: <p>I have an angular app that does lots of asynchronous calls using $http.get, and I have a count variable in my scope ($scope.count) that keeps track of how many requests I made and how many are still pending. Obviously, I'm using it like so:</p>
  
  <ul>
  <li>Before I make a $http.get request I increment the count by 1</li>
  <li>When I get a response from the $http.get I decrement the count by 1</li>
  </ul>
  
  <p>I'm making lots of requests, something around 2000 requests all at the same time, but the $scope.count value is not going back to 0 even after all requests are done, it's always greater than 0 (always off by 1 or 2). I'm handling both success and error events for my $http.get call, and I decrement the count whenever one of them happens.</p>
  
  <p>So I was wondering if angular/javascript handle concurrency well? I'm thinking I'm running the increment operation so many times (potentially many at the same time) and the value of $scope.count becomes obsolete/bad since two operations can be modifying the variable at the same time.</p>