Adding a .finally() method would be nice (src included)
See original GitHub issueAlthough not included in ES6. The finally() method is very valuable.
Here’s one implementation:
Promise.prototype.finally = function(callback) {
var p = this.constructor;
// We don’t invoke the callback in here,
// because we want then() to handle its exceptions
return this.then(
// Callback fulfills: pass on predecessor settlement
// Callback rejects: pass on rejection (=omit 2nd arg.)
function(value) {
p.resolve(callback()).then(function() { return value; });
},
function(reason) {
p.resolve(callback()).then(function() { throw reason; });
}
);
}
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (6 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 >The try-with-resources Statement - Exceptions
Therefore, use a try -with-resources statement instead of a finally block to close your program's resources.
Read more >Python Exception Handling - Try/Except Block, Finally Block
Python Exception Handling - methods to do python exception handling, try cath block, finally block,assertions, Raise keyword, Define your own exceptions.
Read more >Why does a return in `finally` override `try`? - Stack Overflow
Finally always executes. That's what it's for, which means its return value gets used in your case. You'll want to change your code...
Read more >JavaScript try/catch/finally Statement - W3Schools
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP,...
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 Free
Top 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
yeah it’s stage 3 so I guess I can put it in
Thanks