I found a sentence in Chapter 3 "Calling Too Late" that made me scratch my head.
(right below the code snippet)
p.then( function(){
p.then( function(){
console.log( "C" );
} );
console.log( "A" );
} );
p.then( function(){
console.log( "B" );
} );
// A B C
_Here, "C" cannot interrupt and precede "B", by virtue of how Promises are defined to operate._
It looks to me, that it is possible that "C" can precede "B". If "B" takes longer to resolve than "A + C" the results are being logged in the following order. // A C B
So by design, promises do not prevent "C" from preceding "B".
https://jsfiddle.net/datadeer/7u0nk7fp/3/
Am i on to something, or am i missing anything?
If the then(..) calls were on different promises, what you say would be possible. But in the example quoted, all then(..) calls are on the same p promise. As such, once that one p is resolved, all these then(..) registered handlers will run in a single first-come-first-served queue, which would then ensure A B C order.
That makes sense. I haven't thought about that. Thanks for the quick response. :)
Most helpful comment
If the
then(..)calls were on different promises, what you say would be possible. But in the example quoted, allthen(..)calls are on the sameppromise. As such, once that onepis resolved, all thesethen(..)registered handlers will run in a single first-come-first-served queue, which would then ensureA B Corder.