Skip to content

Commit

Permalink
Fixes #166
Browse files Browse the repository at this point in the history
  • Loading branch information
petkaantonov committed Mar 29, 2014
1 parent 4fd92e2 commit d818ff3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/cancel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module.exports = function(Promise, INTERNAL) {
if (!this.isCancellable()) return this;
var parent;
//Propagate to the last cancellable parent
if ((parent = this._cancellationParent) !== void 0) {
if ((parent = this._cancellationParent) !== void 0 &&
parent.isCancellable()) {
parent.cancel(SYNC_TOKEN);
return;
}
Expand Down
39 changes: 38 additions & 1 deletion test/mocha/cancel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ var adapter = require("../../js/debug/bluebird.js");
var fulfilled = adapter.fulfilled;
var rejected = adapter.rejected;
var pending = adapter.pending;

var Promise = adapter;
var delay = Promise.delay;

var sentinel = {
sentinel: "sentinel"
Expand Down Expand Up @@ -241,3 +242,39 @@ describe("Cancel.4: Otherwise the promise is rejected with a CancellationError."
});
});

describe("issues", function(){
specify("gh-166", function(done) {
var f1 = false, f2 = false, f3 = false, f4 = false;
var a = Promise.resolve().cancellable();
a = a.then(function() {
f1 = true;
return delay(35);
});

a = a.then(function() {
f2 = true;
return delay(35);
});

a = a.then(function() {
f3 = true;
return delay(300);
});

a = a.then(function() {
f4 = true;
done(new Error("fail"));
});

a = a.caught(Promise.CancellationError, function() {
assert(f1); assert(f2); assert(f3);
done();
});

assert(a.isCancellable());
setTimeout(function() {
assert(a.isCancellable());
a.cancel();
}, 100);
});
});

0 comments on commit d818ff3

Please sign in to comment.