question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding a .finally() method would be nice (src included)

See original GitHub issue

Although 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:closed
  • Created 8 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
calvinmetcalfcommented, Jan 23, 2018

yeah it’s stage 3 so I guess I can put it in

0reactions
tohagancommented, Jan 24, 2018

Thanks

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found