Promise finally

2018-02-25 Thread Raul-Sebastian Mihăilă
This is an illustration of the current `Promise.prototype.finally` deficiency. In this example, the `incr` method does 2 things. It increases `count` by 1. And increases `methodCallsCount` by 1. At a later point in time, it was decided to add an `incr3` method that did the same, but increase `count

Re: Promise finally

2018-02-25 Thread Raul-Sebastian Mihăilă
I made the PR on the ecma repo so that the diff is smaller (since I'm touching more sections than the proposal repo had). https://github.com/tc39/ecma262/pull/1118/files On Sun, Feb 25, 2018 at 5:27 AM, Jordan Harband wrote: > Simply theorizing about how it might be done - without an actual spec

Re: Promise finally

2018-02-24 Thread Jordan Harband
Simply theorizing about how it might be done - without an actual spec diff (this email might be close but I can't personally reason about it) - isn't going to achieve much, unfortunately. However, if you'd like to make a PR to the proposal repo, I'd be happy to review it. If it seems possible, and

Promise finally

2018-02-24 Thread Raul-Sebastian Mihăilă
Trying better formatting for esdiscuss.org. ``` CreateResolvingFunctions(promise, finallySourcePromise) update step 3: Let resolve be CreateBuiltinFunction(stepsResolve, « [[Promise]], [[AlreadyResolved]], [[FinallySourcePromise]] »). insert new step 6: Set resolve.[[FinallySourcePromise]] to

Promise finally

2018-02-24 Thread Raul-Sebastian Mihăilă
If TC39 finds a better solution than the existing one in good time, I don't think it makes sense for it to wait for another year to implement it while having a broken `Promise.prototype.finally` in the browsers. I've been thinking about a solution and, if my solution is correct, the changes are ve

Re: Promise finally

2018-02-23 Thread Ben Newman
fying 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 editi

Promise finally

2018-02-23 Thread 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 es-disc

Promise finally

2018-02-23 Thread Raul-Sebastian Mihăilă
@Ben Newman There are 2 extra ticks, not just 1. The first one is caused by step 8 of 25.6.5.3.1 and the other one is caused by the fact that the `thenFinally` callback passed in step 7 of 25.6.5.3 returns a promise. I'm wondering if this trade-off is the right one.

Re: Promise finally

2018-02-23 Thread Ben Newman
This ordering of `console.log` calls seems to happen because `Promise.prototype.finally` is specified in terms of `Promise.prototype.then`, and is required to call `.then` twice. Note the `Invoke(promise, "then", « thenFinally, catchFinally »)` here

Re: Promise finally

2018-02-23 Thread Boris Zbarsky
On 2/23/18 9:30 AM, Michael Luder-Rosefield wrote: Whenever you chain a promise with a then/finally, you're basically letting the runtime look at the callbacks at some arbitrary point in the future, no? Not if the promise is already known to be resolved. In that case, the exact behavior of t

Re: Promise finally

2018-02-23 Thread Michael Luder-Rosefield
Whenever you chain a promise with a then/finally, you're basically letting the runtime look at the callbacks at some arbitrary point in the future, no? So despite being written in a defined order, they will be run in whatever order eventuates. On Fri, 23 Feb 2018 at 14:24 Raul-Sebastian Mihăilă w

Re: Promise finally

2018-02-23 Thread Raul-Sebastian Mihăilă
The order is deterministic, as specified, I just don't think it's the right order. I don't have a concrete example with finally, but if I were to imagine one, say you're writing some tests with jest and you want to make some checks in the then callbacks. In order for those checks to be executed in

Re: Promise finally

2018-02-23 Thread Viktor Kronvall
Since these two Promises aren't chained to one another I wouldn't expect any specific deterministic ordering between the `console.log` statements. Are you suggesting that such a deterministic ordering should be imposed by using micro tasks or what are you proposing here exactly? In other words, wh

Promise finally

2018-02-23 Thread Raul-Sebastian Mihăilă
I find it weird that ```js Promise.resolve().finally(() => {}).then(() => { console.log(1); }); Promise.resolve().then(() => {}).then(() => { console.log(2); }); ``` prints 2 and then 1. It would have been possible to spec it in such a way that it would have printed 1 and 2. On the other hand `