Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Promise.prototype.finally #2428

Open
mariusGundersen opened this issue Nov 14, 2023 · 0 comments
Open

Add Promise.prototype.finally #2428

mariusGundersen opened this issue Nov 14, 2023 · 0 comments

Comments

@mariusGundersen
Copy link
Contributor

It seems like finally is missing from Promise prototype. It should be fairly easy to implement as

Promise.prototype.finally = function (f) {
  return this.then(
    (x) => Promise.resolve(f()).then(() => x),
    (x) => Promise.resolve(f()).then(() => Promise.reject(x))
  );
};

finally is called if the original promise resolves or rejects, and does not affect what is passed on in the chain, unless the finally callback throws/rejects.

BTW, there is still a problem with the promise chain, see #2227

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant