I know how to execute multiple ajax calls at once using $.when. E.g.:
$.when( d1, d2 ).done(function ( v1, v2 ) {
console.log( v1 ); // "Fish"
console.log( v2 ); // "Pizza"
})
However, I want to use this in a method so that I can use it multiple times to return a value (e.g.
function getDataFor(list) {
var data = [];
$.when(d1(list), d2(list)).done(function (v1, v2) {
console.log(v1);
console.log(v2);
data = [v1, v2];
});
return data;
}
What is the proper format for this? Also, is it essentially useless to use .then over .done in the above example unless I plan on having another promise follow that one?
edit: I do not feel that this is a duplicate question. Although I understand why it seems like that, I was really just looking to know if there was an out-of-the-box or library-based (e.g., jquery/bluebird) wrapper like .NET's WaitAll method which takes a set of asynchronous calls and blocks the thread until they are all completed. I've accepted that this isn't possible, but I don't feel it is a duplicate.