* @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)
| 16907 | */ |
| 16908 | |
| 16909 | function all(promises) { |
| 16910 | var deferred = new Deferred(), |
| 16911 | counter = 0, |
| 16912 | results = isArray(promises) ? [] : {}; |
| 16913 | |
| 16914 | forEach(promises, function(promise, key) { |
| 16915 | counter++; |
| 16916 | when(promise).then(function(value) { |
| 16917 | results[key] = value; |
| 16918 | if (!(--counter)) deferred.resolve(results); |
| 16919 | }, function(reason) { |
| 16920 | deferred.reject(reason); |
| 16921 | }); |
| 16922 | }); |
| 16923 | |
| 16924 | if (counter === 0) { |
| 16925 | deferred.resolve(results); |
| 16926 | } |
| 16927 | |
| 16928 | return deferred.promise; |
| 16929 | } |
| 16930 | |
| 16931 | /** |
| 16932 | * @ngdoc method |