Permalink
Browse files

Promises should not be able to be canceled more than once.

  • Loading branch information...
1 parent 27fcae7 commit 2d54d664ff977652562e3c707d6819888251046c @fwg fwg committed with ry Nov 22, 2009
Showing with 15 additions and 0 deletions.
  1. +3 −0 src/node.js
  2. +12 −0 test/mjsunit/test-promise-cancel.js
View
@@ -257,6 +257,9 @@ process.Promise.prototype.timeout = function(timeout) {
};
process.Promise.prototype.cancel = function() {
+ if(this._cancelled) return;
+ this._cancelled = true;
+
this._events['success'] = [];
this._events['error'] = [];
@@ -0,0 +1,12 @@
+process.mixin(require('./common'));
+
+var promise = new process.Promise();
+var cancelled = false;
+promise.addCancelback(function(){
+ if(cancelled){
+ assertUnreachable("promise should not cancel more than once");
+ }
+ cancelled = true;
+});
+promise.cancel();
+promise.cancel();

0 comments on commit 2d54d66

Please sign in to comment.