1 define("dojo/promise/all", [
5 ], function(array, Deferred, when){
11 var some = array.some;
13 return function all(objectOrArray){
15 // Takes multiple promises and returns a new promise that is fulfilled
16 // when all promises have been fulfilled.
18 // Takes multiple promises and returns a new promise that is fulfilled
19 // when all promises have been fulfilled. If one of the promises is rejected,
20 // the returned promise is also rejected. Canceling the returned promise will
21 // *not* cancel any passed promises.
22 // objectOrArray: Object|Array?
23 // The promise will be fulfilled with a list of results if invoked with an
24 // array, or an object of results when passed an object (using the same
25 // keys). If passed neither an object or array it is resolved with an
27 // returns: dojo/promise/Promise
30 if(objectOrArray instanceof Array){
31 array = objectOrArray;
32 }else if(objectOrArray && typeof objectOrArray === "object"){
33 object = objectOrArray;
40 for(var key in object){
41 if(Object.hasOwnProperty.call(object, key)){
43 array.push(object[key]);
51 if(!array || !array.length){
52 return new Deferred().resolve(results);
55 var deferred = new Deferred();
56 deferred.promise.always(function(){
57 results = keyLookup = null;
59 var waiting = array.length;
60 some(array, function(valueOrPromise, index){
62 keyLookup.push(index);
64 when(valueOrPromise, function(value){
65 if(!deferred.isFulfilled()){
66 results[keyLookup[index]] = value;
68 deferred.resolve(results);
72 return deferred.isFulfilled();
74 return deferred.promise; // dojo/promise/Promise