Skip to content

Add Promise.prototype.finally #2428

Open
@mariusGundersen

Description

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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions