Commit 38f4a266 authored by Domenic Denicola's avatar Domenic Denicola

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

parent 7a5493c2
......@@ -138,8 +138,12 @@ function all(promises) {
reject(allPromise, error);
};
for (i = 0; i < remaining; i++) {
promises[i].then(resolver(i), rejectAll);
for (i = 0; i < promises.length; i++) {
if (promises[i] && typeof promises[i].then === 'function') {
promises[i].then(resolver(i), rejectAll);
} else {
resolveAll(i, promises[i]);
}
}
return allPromise;
}
......
......@@ -125,5 +125,17 @@ describe("RSVP extensions", function() {
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