Commit a57ca10a authored by Domenic Denicola's avatar Domenic Denicola Committed by Yehuda Katz

Make `RSVP.all` work with more than just promises.

parent b1b2781e
...@@ -138,8 +138,12 @@ function all(promises) { ...@@ -138,8 +138,12 @@ function all(promises) {
reject(allPromise, error); reject(allPromise, error);
}; };
for (i = 0; i < remaining; i++) { for (i = 0; i < promises.length; i++) {
promises[i].then(resolver(i), rejectAll); if (promises[i] && typeof promises[i].then === 'function') {
promises[i].then(resolver(i), rejectAll);
} else {
resolveAll(i, promises[i]);
}
} }
return allPromise; return allPromise;
} }
......
...@@ -125,5 +125,17 @@ describe("RSVP extensions", function() { ...@@ -125,5 +125,17 @@ describe("RSVP extensions", function() {
done(); done();
}); });
}); });
specify('works with a mix of promises and thenables and non-promises', function(done) {
var promise = new RSVP.Promise(function(resolve) { resolve(1); });
var syncThenable = { then: function (onFulfilled) { onFulfilled(2); } };
var asyncThenable = { then: function (onFulfilled) { setTimeout(function() { onFulfilled(3); }, 0); } };
var nonPromise = 4;
RSVP.all([promise, syncThenable, asyncThenable, nonPromise]).then(function(results) {
assert.deepEqual(results, [1, 2, 3, 4]);
done();
});
});
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment