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

Fix Promise.finally Non-standard behavior #293

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions packages/fbjs/src/__forks__/Promise.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ require('promise/setimmediate/done');
/**
* Handle either fulfillment or rejection with the same callback.
*/
Promise.prototype.finally = function(onSettled) {
return this.then(onSettled, onSettled);
};
Promise.prototype.finally = function(callback) {
return this.then(
value => Promise.resolve(callback()).then(() => value),
reason => Promise.resolve(callback()).then(() => {
throw reason;
})
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIWI: We can replace this whole definition with just a call to require('promise/setimmediate/finally'). https://github.com/then/promise/blob/7.3.1/src/finally.js

What you have is virtually identical, just reducing the amount of code we need to have written ourselves.


module.exports = Promise;