I am currently working on implementing a promise in Angular using the $q service to retrieve an object from a web service. The unique aspect of this implementation is that if the object is already cached, it should be returned without making a call to the web service.
However, I am encountering an issue where both resolves are being invoked.
I'm questioning whether or not I might be inadvertently utilizing a promise anti-pattern.
Below is the snippet of my code:
function returnMapAsync() {
return $q(function (resolve, reject) {
if (navigationMap) {
resolve(navigationMap);
} else {
ServerRequest.getNavigationMap().then(function (data) {
navigationMap = data.object;
resolve(navigationMap);
});
}
});
}
Your guidance would be greatly appreciated. Thank you.