Promise finally

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Promise finally

Raul-Sebastian Mihăilă
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
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Promise finally

Ben Newman
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ă <[hidden email]> 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
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss