In Bluebird, when a promise resolves and we resolve it with an array of values - there's an option to use .spread function to separate values back from the array and pass them as arguments for the next .then, like so:
return new Promise(function(resolve, reject){
var val1 = 1;
var val2 = 2;
//Since resolve takes only 1 arg - we join these into array
resolve([val1, val2]);
})
.spread(function(val1, val2){
//val1 and val2 are separate again
});
How do I do this with Q?
It seems to also have a .spread function but it's purpose is to be applied on an array of Promises.
spread()
. Just as in bluebird.