Skip to content

Commit a75e23d

Browse files
committed
Fixed AV.Promise.all
1 parent 38feab9 commit a75e23d

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/promise.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,14 @@
126126

127127
var promise = new AV.Promise();
128128

129-
var resolveOne = function() {
129+
var resolveOne = function(i) {
130130
total = total - 1;
131+
if(hadError && !promise._rejected && isAll) {
132+
return promise.reject(promise, errors[i]);
133+
}
134+
131135
if (total === 0) {
132-
if (hadError) {
136+
if (hadError && !isAll) {
133137
promise.reject(errors);
134138
} else {
135139
if(isAll) {
@@ -145,15 +149,15 @@
145149
if (AV.Promise.is(object)) {
146150
object.then(function(result) {
147151
results[i] = result;
148-
resolveOne();
152+
resolveOne(i);
149153
}, function(error) {
150154
errors[i] = error;
151155
hadError = true;
152-
resolveOne();
156+
resolveOne(i);
153157
});
154158
} else {
155159
results[i] = object;
156-
resolveOne();
160+
resolveOne(i);
157161
}
158162
});
159163

@@ -253,7 +257,8 @@
253257

254258
/**
255259
* Just like AV.Promise.when, but it calls resolveCallbck function
256-
* with one results array.
260+
* with one results array and calls rejectCallback function as soon as one
261+
* of promises rejects.
257262
* @see AV.Promise.when
258263
*/
259264
AV.Promise.all = function(promises) {

0 commit comments

Comments
 (0)