Within my Angular.js application, I am executing an asynchronous operation. To ensure a smooth user experience, I cover the application with a modal div before initiating the operation. Once the operation is complete, regardless of its outcome, I need to remove the div.
Currently, my implementation looks like this:
LoadingOverlay.start();
Auth.initialize().then(function() {
LoadingOverlay.stop();
}, function() {
LoadingOverlay.stop(); // Duplication of code
})
While this method works effectively, I would prefer a cleaner approach akin to the following pseudo-code:
LoadingOverlay.start();
Auth.initialize().finally(function() { // *pseudo-code* - a function that executes on both success and failure.
LoadingOverlay.stop();
})
I suspect that this is a common issue, but I have been unable to find any relevant information in the documentation. Is it possible to achieve this? Any suggestions would be greatly appreciated.