Skip to content

Commit

Permalink
Fixes #362
Browse files Browse the repository at this point in the history
  • Loading branch information
petkaantonov committed Oct 25, 2014
1 parent bf9f64f commit fb7ec48
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cancel.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Promise.prototype._cancel = function Promise$_cancel(reason) {
promiseToReject = parent;
}
ASSERT(promiseToReject.isCancellable());
this._unsetCancellable();
promiseToReject._attachExtraTrace(reason);
promiseToReject._rejectUnchecked(reason);
};
Expand Down
15 changes: 15 additions & 0 deletions test/mocha/cancel.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,18 @@ describe("simple", function() {

});
});

describe("Cancelling a promise twice should have no additional effect", function() {
specify("With delay", function(done) {
var promise = pending().promise.cancellable().catch(function(){}).then(done).catch(function() { done(new Error('Should not be called')) });
promise.cancel();
setTimeout(function() {
promise.cancel();
}, 50);
});
specify("Without delay", function(done) {
var promise = pending().promise.cancellable().catch(function(){}).then(done).catch(function() { done(new Error('Should not be called')) });
promise.cancel()
promise.cancel();
});
});

0 comments on commit fb7ec48

Please sign in to comment.