Skip to content

Instantly share code, notes, and snippets.

@domenic
Last active August 12, 2017 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domenic/080bc9aaa5f22cddeb74810025a2e832 to your computer and use it in GitHub Desktop.
Save domenic/080bc9aaa5f22cddeb74810025a2e832 to your computer and use it in GitHub Desktop.
Promise.prototype.finally observability
// 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