Commit 4118cd40 authored by Tristan Cavelier's avatar Tristan Cavelier

cancel `all` or `any` with non cancellable thenables

parent 34a4233b
......@@ -12,7 +12,8 @@ function promiseAtLeast(expected_count, promises) {
for (var i = 0; i < promises.length; i++) {
promise = promises[i];
if (promise && typeof promise.then === 'function') {
if (promise && typeof promise.then === 'function' &&
typeof promise.cancel === 'function') {
promise.cancel();
}
}
......
......@@ -782,6 +782,40 @@ describe("RSVP extensions", function() {
}, 20);
});
specify('cancel with non cancellable thenables', function(done) {
var firstResolver, secondResolver;
var first = new RSVP.Promise(function(resolve, reject) {
firstResolver = { resolve: resolve, reject: reject };
});
var second = new RSVP.Promise(function(resolve, reject) {
secondResolver = { resolve: resolve, reject: reject };
});
setTimeout(function() {
firstResolver.reject({});
}, 0);
setTimeout(function() {
secondResolver.resolve(true);
}, 5000);
var all_promise = RSVP.all([{"then": function () {
return;
}}, first, second]);
all_promise.cancel();
setTimeout(function() {
assert(first.isRejected);
assert(first.rejectedReason instanceof RSVP.CancellationError);
assert(second.isRejected);
assert(second.rejectedReason instanceof RSVP.CancellationError);
done();
}, 20);
});
specify('notifies promises progress', function(done) {
var firstResolver, secondResolver, count = 0, expected = {};
......@@ -992,6 +1026,40 @@ describe("RSVP extensions", function() {
}, 20);
});
specify('cancel with non cancellable thenables', function(done) {
var firstResolver, secondResolver;
var first = new RSVP.Promise(function(resolve, reject) {
firstResolver = { resolve: resolve, reject: reject };
});
var second = new RSVP.Promise(function(resolve, reject) {
secondResolver = { resolve: resolve, reject: reject };
});
setTimeout(function() {
firstResolver.reject({});
}, 0);
setTimeout(function() {
secondResolver.resolve(true);
}, 5000);
var all_promise = RSVP.any([{"then": function () {
return;
}}, first, second]);
all_promise.cancel();
setTimeout(function() {
assert(first.isRejected);
assert(first.rejectedReason instanceof RSVP.CancellationError);
assert(second.isRejected);
assert(second.rejectedReason instanceof RSVP.CancellationError);
done();
}, 20);
});
specify('notifies promises progress', function(done) {
var firstResolver, secondResolver, count = 0, expected = {};
......
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