* @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)
| 17568 | */ |
| 17569 | |
| 17570 | function all(promises) { |
| 17571 | var result = new Promise(), |
| 17572 | counter = 0, |
| 17573 | results = isArray(promises) ? [] : {}; |
| 17574 | |
| 17575 | forEach(promises, function(promise, key) { |
| 17576 | counter++; |
| 17577 | when(promise).then(function(value) { |
| 17578 | results[key] = value; |
| 17579 | if (!(--counter)) resolvePromise(result, results); |
| 17580 | }, function(reason) { |
| 17581 | rejectPromise(result, reason); |
| 17582 | }); |
| 17583 | }); |
| 17584 | |
| 17585 | if (counter === 0) { |
| 17586 | resolvePromise(result, results); |
| 17587 | } |
| 17588 | |
| 17589 | return result; |
| 17590 | } |
| 17591 | |
| 17592 | /** |
| 17593 | * @ngdoc method |
nothing calls this directly
no test coverage detected