I\'m still learning JavaScript Promises, and I came across a behavior I don\'t understand.
What does r() do?
The ordering is indeterminate because you're thenning on the same promise -> this specifically refers to the second and third chain.
If you were doing the following, then order can be guaranteed:
var p = Promise.resolve().then(function() {
w(0);
}).then(function() {
w(1);
});
// Key difference, continuing the promise chain "correctly".
p = p.then(function() {
w(2);
return new Promise(function(r) {
w(3);
r();
}).then(function() {
w(4);
});
}).then(function() {
w(5);
});
p.then(function() {
w(6);
});