* @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)
| 18186 | */ |
| 18187 | |
| 18188 | function all(promises) { |
| 18189 | var result = new Promise(), |
| 18190 | counter = 0, |
| 18191 | results = isArray(promises) ? [] : {}; |
| 18192 | |
| 18193 | forEach(promises, function(promise, key) { |
| 18194 | counter++; |
| 18195 | when(promise).then(function(value) { |
| 18196 | results[key] = value; |
| 18197 | if (!(--counter)) resolvePromise(result, results); |
| 18198 | }, function(reason) { |
| 18199 | rejectPromise(result, reason); |
| 18200 | }); |
| 18201 | }); |
| 18202 | |
| 18203 | if (counter === 0) { |
| 18204 | resolvePromise(result, results); |
| 18205 | } |
| 18206 | |
| 18207 | return result; |
| 18208 | } |
| 18209 | |
| 18210 | /** |
| 18211 | * @ngdoc method |
nothing calls this directly
no test coverage detected