Commit 5cf9be38 authored by Romain Courteaud's avatar Romain Courteaud

promise: canceller block all callbacks

parent a61853dc
......@@ -49,6 +49,7 @@ var Promise = function(resolver, canceller) {
// For now, simply reject the promise and does not propagate the cancel
// to parent or children
if (resolved) { return; }
promise.isCancelled = true;
if (canceller !== undefined) {
try {
canceller();
......@@ -80,6 +81,7 @@ var invokeCallback = function(type, promise, callback, event) {
if (promise.isFulfilled) { return; }
if (promise.isRejected) { return; }
if (promise.isCancelled) { return; }
if (hasCallback) {
try {
......@@ -110,6 +112,7 @@ var invokeCallback = function(type, promise, callback, event) {
Promise.prototype = {
constructor: Promise,
isCancelled: undefined,
isRejected: undefined,
isFulfilled: undefined,
rejectedReason: undefined,
......
......@@ -1513,6 +1513,7 @@ describe("RSVP extensions", function() {
wrapped.cancel();
});
});
});
});
......@@ -1734,14 +1735,16 @@ describe("`cancel` on promise created by then", function () {
});
it('should stop parent fulFillment propagation', function (done) {
var promise = new RSVP.resolve(1),
promise2 = promise.then();
var resolve_count = 0,
promise = new RSVP.resolve(1),
promise2 = promise.then(function () {resolve_count += 1;});
promise2.cancel("Foo");
setTimeout(function() {
assert.equal(promise2.isRejected, true);
assert.equal(promise2.isFulfilled, undefined);
assert(promise2.rejectedReason instanceof RSVP.CancellationError);
assert.equal(resolve_count, 0);
done();
}, 20);
});
......@@ -1756,12 +1759,12 @@ describe("`cancel` on promise created by then", function () {
assert.equal(promise2.isRejected, true);
assert.equal(promise2.isFulfilled, undefined);
assert(promise2.rejectedReason instanceof RSVP.CancellationError);
assert.equal(reject_count, 1);
assert.equal(reject_count, 0);
done();
}, 20);
});
it('should not be callable twice', function (done) {
it('should be callable twice', function (done) {
var reject_count = 0,
promise = new RSVP.reject(1),
promise2 = promise.fail(function () {reject_count += 1;});
......@@ -1772,7 +1775,7 @@ describe("`cancel` on promise created by then", function () {
assert.equal(promise2.isRejected, true);
assert.equal(promise2.isFulfilled, undefined);
assert(promise2.rejectedReason instanceof RSVP.CancellationError);
assert.equal(reject_count, 1);
assert.equal(reject_count, 0);
done();
}, 20);
});
......
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