Commit 34045c37 authored by Romain Courteaud's avatar Romain Courteaud

Make RSVP#all cancellable.

Cancel all sub promises as soon as cancelled.
parent 543306a7
......@@ -37,6 +37,15 @@ function all(promises) {
resolveAll(i, promise);
}
}
}, function() {
var promise;
for (var i = 0; i < promises.length; i++) {
promise = promises[i];
if (promise && typeof promise.then === 'function') {
promise.cancel();
}
}
});
}
......
......@@ -691,6 +691,38 @@ describe("RSVP extensions", function() {
done();
});
});
specify('cancel the array of promise as soon as cancelled', 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(["nonPromiseValue", 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);
});
});
describe("RSVP.reject", function(){
......
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