<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: http://www.jeditoolkit.com/</div><div><br></div></div>
<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>