The following Promise
behaves as expected, the Promise
in the return
statement gets fulfilled and the then
right afterwards gets executed before the last call of then:
(new Promise(resolve => resolve(true)))
.then(function(){
console.log(0);
return new Promise(resolve => setTimeout(resolve, 1000))
.then(function() {
console.log(1);
});
}).then(function() {
console.log(2);
});
The result is
0
1
2
But when the first Promise
is a jQuery Promise
like in the following case
$.post("index.php")
.then(function() {
console.log(0);
return new Promise(resolve => setTimeout(resolve, 1000))
.then(function() {
console.log(1);
});
}).then(function() {
console.log(2);
});
the result is
0 2 1
which indicates, that the second Promise
is not passed on as in standard JavaScript promises.
Is there a way to force the standard behavior?
I'm using jQuery 2.0.0.