Last active
August 12, 2017 16:30
-
-
Save domenic/080bc9aaa5f22cddeb74810025a2e832 to your computer and use it in GitHub Desktop.
Promise.prototype.finally observability
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Current spec | |
function finally(onFinally) { | |
let C = SpeciesConstructor(this); | |
return this.then( | |
x => new C(r => r(onFinally())).then(() => x), | |
e => new C(r => r(onFinally())).then(() => { throw e; }) | |
); | |
} | |
// Proposed, but rejected (potentially because of a miscommunication) spec | |
function finally(onFinally) { | |
return builtInPromiseThen( | |
this, | |
x => builtinPromiseThen(BuiltinPromiseResolve(onFinally()), () => x), | |
e => builtinPromiseThen(BuiltinPromiseResolve(onFinally()), () => { throw e; }) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment