Bugfix, Promise.timeout() blocked the event loop

Promise.timeout() was blocking the event loop from shutting down while it
was waiting for an internal timer to fire. This timer is now cleared when
it is no longer needed, causing the event loop to shut down as fast as
possible.
This commit is contained in:
Felix Geisendörfer 2009-11-12 12:35:27 +01:00 committed by Ryan Dahl
parent bffee5eda4
commit bb8f0725da

View File

@ -215,11 +215,16 @@ process.Promise.prototype.timeout = function(timeout) {
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
@ -227,8 +232,9 @@ process.Promise.prototype.timeout = function(timeout) {
.addCancelback(onComplete)
.addErrback(onComplete);
var self = this
var self = this;
this._timer = setTimeout(function() {
self._timer = null;
if (promiseComplete) {
return;
}