mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-09 07:14:44 +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,
|
counter = promises.length,
|
||||||
results = [];
|
results = [];
|
||||||
|
|
||||||
forEach(promises, function(promise, index) {
|
if (counter) {
|
||||||
promise.then(function(value) {
|
forEach(promises, function(promise, index) {
|
||||||
if (index in results) return;
|
ref(promise).then(function(value) {
|
||||||
results[index] = value;
|
if (index in results) return;
|
||||||
if (!(--counter)) deferred.resolve(results);
|
results[index] = value;
|
||||||
}, function(reason) {
|
if (!(--counter)) deferred.resolve(results);
|
||||||
if (index in results) return;
|
}, function(reason) {
|
||||||
deferred.reject(reason);
|
if (index in results) return;
|
||||||
|
deferred.reject(reason);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
} else {
|
||||||
|
deferred.resolve(results);
|
||||||
|
}
|
||||||
|
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -676,6 +676,14 @@ describe('q', function() {
|
||||||
|
|
||||||
|
|
||||||
describe('all', 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() {
|
it('should take an array of promises and return a promise for an array of results', function() {
|
||||||
var deferred1 = defer(),
|
var deferred1 = defer(),
|
||||||
deferred2 = defer();
|
deferred2 = defer();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue