mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
fix(q): resolve all of nothing to nothing
$q.all([]) no longer throws exception and resolves to empty array []
This commit is contained in:
parent
5390fb37d2
commit
ac75079e21
2 changed files with 21 additions and 9 deletions
|
|
@ -364,16 +364,20 @@ function qFactory(nextTick, exceptionHandler) {
|
|||
counter = promises.length,
|
||||
results = [];
|
||||
|
||||
forEach(promises, function(promise, index) {
|
||||
promise.then(function(value) {
|
||||
if (index in results) return;
|
||||
results[index] = value;
|
||||
if (!(--counter)) deferred.resolve(results);
|
||||
}, function(reason) {
|
||||
if (index in results) return;
|
||||
deferred.reject(reason);
|
||||
if (counter) {
|
||||
forEach(promises, function(promise, index) {
|
||||
ref(promise).then(function(value) {
|
||||
if (index in results) return;
|
||||
results[index] = value;
|
||||
if (!(--counter)) deferred.resolve(results);
|
||||
}, function(reason) {
|
||||
if (index in results) return;
|
||||
deferred.reject(reason);
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
deferred.resolve(results);
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -676,6 +676,14 @@ describe('q', function() {
|
|||
|
||||
|
||||
describe('all', function() {
|
||||
it('should resolve all of nothing', function() {
|
||||
var result;
|
||||
q.all([]).then(function(r) { result = r; });
|
||||
mockNextTick.flush();
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
|
||||
|
||||
it('should take an array of promises and return a promise for an array of results', function() {
|
||||
var deferred1 = defer(),
|
||||
deferred2 = defer();
|
||||
|
|
|
|||
Loading…
Reference in a new issue