* @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)
| 17383 | */ |
| 17384 | |
| 17385 | function all(promises) { |
| 17386 | var result = new Promise(), |
| 17387 | counter = 0, |
| 17388 | results = isArray(promises) ? [] : {}; |
| 17389 | |
| 17390 | forEach(promises, function(promise, key) { |
| 17391 | counter++; |
| 17392 | when(promise).then(function(value) { |
| 17393 | results[key] = value; |
| 17394 | if (!(--counter)) resolvePromise(result, results); |
| 17395 | }, function(reason) { |
| 17396 | rejectPromise(result, reason); |
| 17397 | }); |
| 17398 | }); |
| 17399 | |
| 17400 | if (counter === 0) { |
| 17401 | resolvePromise(result, results); |
| 17402 | } |
| 17403 | |
| 17404 | return result; |
| 17405 | } |
| 17406 | |
| 17407 | /** |
| 17408 | * @ngdoc method |
nothing calls this directly
no test coverage detected