<div dir="ltr"><div>Yeah.  I'm not saying getting it right is impossible (or I'd be strongly anti-sync-promises), just that getting it right requires education and discipline.  And the end result is hard to reliably test.  So it feels like a short opt-in (syncThen() or something) is a reasonable thing for someone to do if they have the right education and discipline.<br>
<br></div><div>Obviously my example was contrived.  If you want to dump 312 you can type dump("312").  But all the way up the callstack every caller needs to be durable against something maybe-happened-and-maybe-didn't.<br>
</div><div><br></div>(particularly if our default behavior adds a pitfall that someone that thinks they know promises from another environment can hit).<br><div><br>-dave<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Thu, Apr 4, 2013 at 1:12 PM, Irakli Gozalishvili <span dir="ltr"><<a href="mailto:gozala@mozilla.com" target="_blank">gozala@mozilla.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

                <div>
                    <span style="font-size:14px">Another solution to just be extremely clear that no assumptions about call order can be made, and that code above can print either 123 or 312 and that may depend on the state of the runtime, same as timeouts don't make strong guarantees. And educate consumer agains such assumptions, by suggesting solution for both cases:</span></div>
<div><span style="font-size:14px"><br></span></div><div><span style="font-size:14px">If You want to print 312 just do</span>
                </div><div><span style="font-size:14px"><br></span></div><div><span style="font-size:14px">dump(3)</span></div><div><span style="font-size:14px">foo().then(=> dump(1)).then(dump(2))</span></div><div><span style="font-size:14px"><br>
</span></div><div><span style="font-size:14px">If you want 123 then include last bit in the chain:</span></div><div><span style="font-size:14px"><br></span></div><div><span style="font-size:14px">foo().then(=> dump(1)).then(=> dump(2)).then(=> dump(3))</span></div>
<div><br></div>
                <div><div><br></div><div style="font-size:14px">--</div><div style="font-size:14px">Irakli Gozalishvili</div><div style="font-size:14px">Web: <a href="http://www.jeditoolkit.com/" target="_blank">http://www.jeditoolkit.com/</a></div>
<div><br></div></div><div class="HOEnZb"><div class="h5">
                 
                <p style="color:#a0a0a8">On Thursday, 2013-04-04 at 12:08 , Dave Townsend wrote:</p>
                <blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px">
                    <span><div><div><div dir="ltr"><br><div>On Thu, Apr 4, 2013 at 11:47 AM, Dave Camp <span dir="ltr"><<a href="mailto:dcamp@mozilla.com" target="_blank">dcamp@mozilla.com</a>></span> wrote:<br><div>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div>I think the problem some people have with non-deferred-promises is that given the following code:<br>

---<br></div>foo().then( ){<br></div>  dump("1");<br></div><div>  return nextTickPromise();<br>
</div>}).then(function() {<br></div><div>  dump("2");<br></div>});<br><br></div><div>dump("3");<br></div><div>---<br></div><div><br></div><div>Whether you get "123" or "312" depends on the implementation of foo().  And if it's sync today, you have no guarantee that it will stay that way (like mconnor said - if you had such a guarantee you wouldn't be using promises).  With async promises you can guarantee that order will be 321.<br>

</div></div></blockquote><div><br></div><div>You mean 312 right?<br></div><div><br></div><div>There are also two parts that we should be careful about conflating. One is whether calling then() on an already resolved promise will call the callbacks before then() returns. A+ says this should never happen and it alone would serve to ensure the order of events above is 312. The other part is whether resolving a promise returns before starting to call callbacks. Maybe that part is less of a concern.<br>

</div></div></div></div>
</div></div></span>
                 
                 
                 
                 
                </blockquote>
                 
                <div>
                    <br>
                </div>
            </div></div></blockquote></div><br></div>