feat(finally): finally should receive as parameter the state of the promise
See original GitHub issueAs per https://github.com/angular/angular.js/issues/9246 , it would be nice and more developer friendly to be able to receive the state of the promise inside the finally call.
My suggestion is for .fin() to receive 2 parameters:
- a boolean – if the promise was resolved (TRUE) or rejected (FALSE)
- a mixed – value sent to .resolve() or .reject()
@kriskowal : what do you think?
I’ll post here the real use-case again. We have a SPA and we are using AngularJS as a framework. I know Q service is a bit different than AngularJS $q, but the logic seems to be very similar.
Our use-case is when all the ajax requests (error or success) may contain a set of messages - those messages should be automatically pushed to the messages component and be shown. The problem is that we have to write:
.then(
function (data) {
msgService.notify(data);
},
function (data) {
msgService.notify(data);
}
);
My suggestion was to have something like:
.then(...)
.finally(function (isResolved, data) {
msgService.notify(data);
});
We can even adapt our notify and just put “.finally(msgService.notify)”.
Issue Analytics
- State:
- Created 9 years ago
- Comments:32 (2 by maintainers)
Top Results From Across the Web
Promise.prototype.finally() - JavaScript - MDN Web Docs
The finally() method of a Promise object schedules a function to be called when the promise is settled (either fulfilled or rejected).
Read more >JavaScript Promise finally() Method - GeeksforGeeks
The finally() method of the Promise object is used to return a Promise when a Promise is settled, that is, it is either...
Read more >How do I access previous promise results in a .then() chain?
These state objects accumulate the results of the previous actions, handing down all values that will be needed later again plus the result...
Read more >JavaScript Promise finally()
Summary: in this tutorial, you will learn how to use the JavaScript Promise finally() method to execute the code once the promise is...
Read more >Delivering on the Promise
Finally, this report was made possible by support from the Ewing Marion Kauffman Foundation, ... collect for their oversight of charter schools is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@domenic How would you implement something like
Below code doesn’t work since
.finally()
doesn’t take any argumentsOne way to do that is
Any other cleaner way to achieve the same?
That train has sailed by now -
finally
is part of JavaScript.Also, you should just do:
Promise.reject(new Error(“boo!”)) .then(function () { console.log(“I should be called only if there is no error”); }, function () { console.log(‘it should not go to next promise’) });
Or, for this behavior do what synchronous code would (and rethrow the error with a
throw
).Also, it is considered bad etiquette to bump issues from 2014