Recently, I've encountered a slow server while trying to pull data from a service using a restangular call. In light of this, I'm exploring ways to potentially abort the call (or just the promise) if a newer call is made, allowing my service to use the most up-to-date information available. Here's the snippet of code for the service call:
MySearchService.prototype.search = function(query) {
return $q(function(resolve, reject) {
var url = '/services/search';
Restangular.oneUrl(url, url)
.customPOST(query)
.then(resolve)
.catch(reject);
});
};
I had an idea like this:
.withHttpConfig({hasNewSearch: abort.promise}) <<not sure you can put custom key in here
abort.resolve();
However, I am unsure if that's the correct way to approach it. Is there a way to cancel the call if a newer request is initiated? It might be related more to the promise aspect rather than restangular itself. Any insights or advice on this matter would be greatly appreciated. Thank you!