* @ngdoc method * @name $q#all * @kind function * * @description * Combines multiple promises into a single promise that is resolved when all of the input * promises are resolved. * * @param {Array. |Object. } promises An array or hash of promises. * @retur
(promises)
| 11974 | * with the same rejection value. |
| 11975 | */ |
| 11976 | function all(promises) { |
| 11977 | var deferred = defer(), |
| 11978 | counter = 0, |
| 11979 | results = isArray(promises) ? [] : {}; |
| 11980 | |
| 11981 | forEach(promises, function(promise, key) { |
| 11982 | counter++; |
| 11983 | ref(promise).then(function(value) { |
| 11984 | if (results.hasOwnProperty(key)) return; |
| 11985 | results[key] = value; |
| 11986 | if (!(--counter)) deferred.resolve(results); |
| 11987 | }, function(reason) { |
| 11988 | if (results.hasOwnProperty(key)) return; |
| 11989 | deferred.reject(reason); |
| 11990 | }); |
| 11991 | }); |
| 11992 | |
| 11993 | if (counter === 0) { |
| 11994 | deferred.resolve(results); |
| 11995 | } |
| 11996 | |
| 11997 | return deferred.promise; |
| 11998 | } |
| 11999 | |
| 12000 | return { |
| 12001 | defer: defer, |