<div dir="ltr"><div>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.</div><div><br></div><div>Note the `Invoke(promise, "then", <span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">«</span> thenFinally, catchFinally <span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">»</span>)` <a href="https://tc39.github.io/ecma262/#sec-promise.prototype.finally">here</a>, followed by `Invoke(promise, "then", « ... »)` <a href="https://tc39.github.io/ecma262/#sec-thenfinallyfunctions">here</a> (and <a href="https://tc39.github.io/ecma262/#sec-catchfinallyfunctions">here</a>).</div><div><br></div><div>Any way you cut it, this adds an extra asynchronous tick/step/hop/skip/jump, compared to merely calling `Promise.prototype.then`.</div><div><br></div><div>Implementing `Promise` extensions in terms of `Promise.prototype.then` is a good idea, because it means we don't have to add new fundamental operations to the core `Promise` implementation. However, the translation from `.finally` to `.then` comes at a cost. Once you understand that tradeoff, hopefully this behavior seems more reasonable.</div><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div>Ben<br></div><br>His errors are volitional and are the portals of discovery.<br>-- James Joyce</div></div></div>
<div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 23, 2018 at 9:32 AM, Boris Zbarsky <span dir="ltr"><<a href="mailto:bzbarsky@mit.edu" target="_blank">bzbarsky@mit.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">On 2/23/18 9:30 AM, Michael Luder-Rosefield wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
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?<br>
</blockquote>
<br></span>
Not if the promise is already known to be resolved.  In that case, the exact behavior of the runtime is very clearly specified.<span class="gmail-HOEnZb"><font color="#888888"><br>
<br>
-Boris</font></span><div class="gmail-HOEnZb"><div class="gmail-h5"><br>
______________________________<wbr>_________________<br>
es-discuss mailing list<br>
<a href="mailto:es-discuss@mozilla.org" target="_blank">es-discuss@mozilla.org</a><br>
<a href="https://mail.mozilla.org/listinfo/es-discuss" rel="noreferrer" target="_blank">https://mail.mozilla.org/listi<wbr>nfo/es-discuss</a><br>
</div></div></blockquote></div><br></div></div>