Browse Source

FIX: Promise timeout should not addErrback

Because now, we expect the exception to be thrown if no errback
is given, we can't let timeout() add an errback silently.
v0.7.4-release
Jonas Pfenniger 15 years ago
committed by Ryan Dahl
parent
commit
971f43d63b
  1. 37
      src/node.js

37
src/node.js

@ -202,45 +202,39 @@ var eventsModule = createInternalModule('events', function (exports) {
process.Promise = exports.Promise;
exports.Promise.prototype.timeout = function(timeout) {
if (timeout === undefined) {
if (!timeout) {
return this._timeoutDuration;
}
this._timeoutDuration = timeout;
if (this._timer) {
clearTimeout(this._timer);
this._timer = null;
}
var promiseComplete = false;
var onComplete = function() {
promiseComplete = true;
if (this._timer) {
clearTimeout(this._timer);
this._timer = null;
}
};
this
.addCallback(onComplete)
.addErrback(onComplete);
if (this.hasFired) return;
this._clearTimeout();
var self = this;
this._timer = setTimeout(function() {
self._timer = null;
if (promiseComplete) {
if (self.hasFired) {
return;
}
self.emitError(new Error('timeout'));
}, this._timeoutDuration);
}, timeout);
return this;
};
exports.Promise.prototype._clearTimeout = function() {
if (!this._timer) return;
clearTimeout(this._timer);
this._timer = null;
}
exports.Promise.prototype.emitSuccess = function() {
if (this.hasFired) return;
this.hasFired = true;
this._clearTimeout();
this._values = Array.prototype.slice.call(arguments);
this.emit.apply(this, ['success'].concat(this._values));
@ -249,6 +243,7 @@ var eventsModule = createInternalModule('events', function (exports) {
exports.Promise.prototype.emitError = function() {
if (this.hasFired) return;
this.hasFired = true;
this._clearTimeout();
this._values = Array.prototype.slice.call(arguments);
this.emit.apply(this, ['error'].concat(this._values));

Loading…
Cancel
Save