* @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)
| 17612 | */ |
| 17613 | |
| 17614 | function all(promises) { |
| 17615 | var result = new Promise(), |
| 17616 | counter = 0, |
| 17617 | results = isArray(promises) ? [] : {}; |
| 17618 | |
| 17619 | forEach(promises, function(promise, key) { |
| 17620 | counter++; |
| 17621 | when(promise).then(function(value) { |
| 17622 | results[key] = value; |
| 17623 | if (!(--counter)) resolvePromise(result, results); |
| 17624 | }, function(reason) { |
| 17625 | rejectPromise(result, reason); |
| 17626 | }); |
| 17627 | }); |
| 17628 | |
| 17629 | if (counter === 0) { |
| 17630 | resolvePromise(result, results); |
| 17631 | } |
| 17632 | |
| 17633 | return result; |
| 17634 | } |
| 17635 | |
| 17636 | /** |
| 17637 | * @ngdoc method |
nothing calls this directly
no test coverage detected