* @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)
| 18251 | */ |
| 18252 | |
| 18253 | function all(promises) { |
| 18254 | var result = new Promise(), |
| 18255 | counter = 0, |
| 18256 | results = isArray(promises) ? [] : {}; |
| 18257 | |
| 18258 | forEach(promises, function(promise, key) { |
| 18259 | counter++; |
| 18260 | when(promise).then(function(value) { |
| 18261 | results[key] = value; |
| 18262 | if (!(--counter)) resolvePromise(result, results); |
| 18263 | }, function(reason) { |
| 18264 | rejectPromise(result, reason); |
| 18265 | }); |
| 18266 | }); |
| 18267 | |
| 18268 | if (counter === 0) { |
| 18269 | resolvePromise(result, results); |
| 18270 | } |
| 18271 | |
| 18272 | return result; |
| 18273 | } |
| 18274 | |
| 18275 | /** |
| 18276 | * @ngdoc method |
nothing calls this directly
no test coverage detected