I have a somewhat complicated scenario and I'm not quite understanding why my call to Q.all
is not returning an array of resolved promises. It is a mix of jQuery $.ajax
calls and Q.
calls. Here is the setup:
var saveThing1 = function(){
return $.ajax({...});
}
var saveThing2 = function(){
return $ajax({...});
}
var deleteThing2 = function(){
return $.ajax({...});
}
saveThing1.then(function(){
var promiseArr = [saveThing2(), saveThing2(), deleteThing2()];
return Q.all(promiseArr);
}).then(function(response){
var result1 = response[0];
var result2 = response[1];
var result3 = response[2];
});
promise.all()
Returns a promise that is fulfilled with an array containing the fulfillment value of each promise, or is rejected with the same rejection reason as the first promise to be rejected.
The value of response
in this case ends up being the single Promise instead of the array of promise values. This is what the Chrome Dev Tools produces when I pause the debugger and log what the response
value is:
Promise {}
inspect:()
promiseDispatch:(resolve, op, operands)
valueOf:()
Another thing that I'm still scratching my head at is that the .then
gets hit while the network requests are still pending, which means the promises in the array passed to Q.all
should also be pending...