Browsers will only allow around 10 concurrent ajax requests (varies slightly per browser). So if I queue up 100 ajax requests, the browser will send 10 of them, and the other 90 pick their noses until one of the other requests finishes.
If the user clicks "cancel" in my UI, I can cancel ALL of the executing requests using the following technique (suggested in this answer):
var canceler = $q.defer();
angular.forEach(itemThatNeedsUpdating, function(item) {
var urlForUpdatingMyItem = getUrl(item),
myData = getData(item);
$http.post(urlForUpdatingMyItem, myData, {timeout: canceler.promise}).success(successCallback);
});
...
// later, after the user clicks "cancel"
canceler.resolve();
That's all good, except that it also cancels the 10 requests that the server is already processing, so the browser will have no way of knowing what happened with them (if they succeeded, etc.). It would be nice if it were possible to cancel only the 90 requests that the server doesn't know about yet and let the other 10 complete as normal. Is there a way to do that?
Alternatively, if there is a way to detect, on the server side (I'm using Django on the server side), that the client cancelled the request so that I can roll back any transactions, that would work too (even better). I can see that the web server can tell when my client cancels the request, but it doesn't appear that that information gets communicated to my Django app (the web server doesn't appear notice the cancel until AFTER Django is completely done building the response and passes it back to the web server).