Permalink
Browse files

Removed Promise.cancel()

The current implementation was bad and nobody is using it. Has a chance
of getting re-implemented by somebody who has an actual need for it.
  • Loading branch information...
1 parent 4e16e38 commit f2274840a9737df45135fffaaaa9da266dbfd66a @felixge felixge committed with ry Jan 19, 2010
Showing with 1 addition and 78 deletions.
  1. +1 −16 doc/api.txt
  2. +0 −21 src/node.js
  3. +0 −13 test/mjsunit/test-promise-cancel.js
  4. +0 −28 test/mjsunit/test-promise-timeout.js
View
17 doc/api.txt
@@ -286,7 +286,6 @@ emit anymore events.
| Event | Parameters | Notes
| +"success"+ | (depends) |
| +"error"+ | (depends) |
-| +"cancel"+ | (depends) |
|=========================================================
+promise.addCallback(listener)+ ::
@@ -295,9 +294,6 @@ Adds a listener for the +"success"+ event. Returns the same promise object.
+promise.addErrback(listener)+ ::
Adds a listener for the +"error"+ event. Returns the same promise object.
-+promise.addCancelback(listener)+ ::
-Adds a listener for the +"cancel"+ event. Returns the same promise object.
-
+promise.emitSuccess(arg1, arg2, ...)+ ::
If you created the promise (by doing +new events.Promise()+) then call
+emitSuccess+ to emit the +"success"+ event with the given arguments.
@@ -308,21 +304,10 @@ the moment due to a bug; use +emitSuccess+ instead.)
+promise.emitError(arg1, arg2, ...)+ ::
Emits the +"error"+ event.
-+promise.emitCancel(arg1, arg2, ...)+ ::
-Emits the +"cancel"+ event. You may still get a +"success"+ or +"error"+
-callback if the promise giver does not handle the cancel event. Use
-+promise.cancel()+ to ignore any later events.
-
-+promise.cancel()+ ::
-Clears all +"success"+ and +"error"+ event listeners from the promise, then
-emits the +"cancel"+ event. Whether or not the promise is actually canceled
-or not depends on the promise giver. This also clears Promise.timeout() if one
-was set.
-
+promise.timeout(timeout = undefined)+ ::
If the +timeout+ parameter is provided, the promise will emit an +"error"+
event after the given amount of millseconds. The timeout is canceled by any
-+"success"+, +"error"+ or +"cancel"+ event being emitted by the Promise.
++"success"+ or +"error"+ event being emitted by the Promise.
+
To tell apart a timeout from a regular "error" event, use the following test:
+
View
21 src/node.js
@@ -259,7 +259,6 @@ var eventsModule = createInternalModule('events', function (exports) {
this
.addCallback(onComplete)
- .addCancelback(onComplete)
.addErrback(onComplete);
var self = this;
@@ -275,21 +274,6 @@ var eventsModule = createInternalModule('events', function (exports) {
return this;
};
- exports.Promise.prototype.cancel = function() {
- if(this._cancelled) return;
- this._cancelled = true;
-
- this._events['success'] = [];
- this._events['error'] = [];
-
- this.emitCancel();
- };
-
- exports.Promise.prototype.emitCancel = function() {
- Array.prototype.unshift.call(arguments, 'cancel')
- this.emit.apply(this, arguments);
- };
-
exports.Promise.prototype.emitSuccess = function() {
if (this.hasFired) return;
this.hasFired = true;
@@ -314,11 +298,6 @@ var eventsModule = createInternalModule('events', function (exports) {
return this;
};
- exports.Promise.prototype.addCancelback = function (listener) {
- this.addListener("cancel", listener);
- return this;
- };
-
/* Poor Man's coroutines */
var coroutineStack = [];
View
13 test/mjsunit/test-promise-cancel.js
@@ -1,13 +0,0 @@
-process.mixin(require('./common'));
-events = require('events');
-
-var promise = new events.Promise();
-var cancelled = false;
-promise.addCancelback(function(){
- if(cancelled){
- assert.ok(false, "promise should not cancel more than once");
- }
- cancelled = true;
-});
-promise.cancel();
-promise.cancel();
View
28 test/mjsunit/test-promise-timeout.js
@@ -51,34 +51,6 @@ errorPromise.addErrback(function(e) {
assert.equal('intentional', e.message);
});
-var cancelPromise = new events.Promise();
-cancelPromise.timeout(500);
-setTimeout(function() {
- cancelPromise.cancel();
-}, 250);
-
-setTimeout(function() {
- cancelPromise.emitSuccess('should be ignored');
-}, 400);
-
-cancelPromise.addCallback(function(e) {
- assert.ok(false, 'addCallback should not fire if the promise is canceled');
-});
-
-cancelPromise.addErrback(function(e) {
- assert.ok(false, 'addErrback should not fire if the promise is canceled');
-});
-
-var cancelTimeoutPromise = new events.Promise();
-cancelTimeoutPromise.timeout(500);
-setTimeout(function() {
- cancelPromise.emitCancel();
-}, 250);
-
-cancelPromise.addErrback(function(e) {
- assert.ok(false, 'addErrback should not fire after a cancel event');
-});
-
process.addListener('exit', function() {
assert.equal(2, timeouts);
});

0 comments on commit f227484

Please sign in to comment.