Promise finally

Ben Newman benjamin at cs.stanford.edu
Fri Feb 23 15:29:56 UTC 2018


Yes, indeed, I should have said "is required to call `.then` *at least*
twice."

It's funny you should mention this nuance, because I recently opened a pull
request against the `Promise.prototype.finally` proposal repository that
would solve exactly this problem, as well as simplifying polyfills by
removing the need for species constructor logic:
https://github.com/tc39/proposal-promise-finally/pull/48

I'm fully aware that my PR came too late to affect the most recent edition
of the spec, but perhaps it's not too late to change this behavior in the
next edition. I would be willing to champion this refinement to the
`Promise.prototype.finally` spec text, if TC39 is open to creating fewer
promise objects and calling `.then` fewer times, at the expense of altering
observable spec semantics (only slightly, I would argue, but observably).

Ben

Ben

His errors are volitional and are the portals of discovery.
-- James Joyce

On Fri, Feb 23, 2018 at 10:19 AM, Raul-Sebastian Mihăilă <
raul.mihaila at gmail.com> wrote:

> In other words
>
> ```js
> Promise.resolve().finally(() => {}).then(() => { console.log(1); });
> Promise.resolve().then(() => {}).then(() => { console.log(2); }).then(()
> => { console.log(3); });
> ```
>
> prints 2, then 3, then 1.
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180223/5df8b6d9/attachment-0001.html>


More information about the es-discuss mailing list