Browse Source

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

v0.7.4-release
Friedemann Altrock 15 years ago
committed by Ryan Dahl
parent
commit
2d54d664ff
  1. 3
      src/node.js
  2. 12
      test/mjsunit/test-promise-cancel.js

3
src/node.js

@ -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'] = [];

12
test/mjsunit/test-promise-cancel.js

@ -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();
Loading…
Cancel
Save