Browse Source

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.
v0.7.4-release
Felix Geisendörfer 15 years ago
committed by Ryan Dahl
parent
commit
bb8f0725da
  1. 8
      src/node.js

8
src/node.js

@ -215,11 +215,16 @@ process.Promise.prototype.timeout = function(timeout) {
this._timeoutDuration = timeout; this._timeoutDuration = timeout;
if (this._timer) { if (this._timer) {
clearTimeout(this._timer); clearTimeout(this._timer);
this._timer = null;
} }
var promiseComplete = false; var promiseComplete = false;
var onComplete = function() { var onComplete = function() {
promiseComplete = true; promiseComplete = true;
if (this._timer) {
clearTimeout(this._timer);
this._timer = null;
}
}; };
this this
@ -227,8 +232,9 @@ process.Promise.prototype.timeout = function(timeout) {
.addCancelback(onComplete) .addCancelback(onComplete)
.addErrback(onComplete); .addErrback(onComplete);
var self = this var self = this;
this._timer = setTimeout(function() { this._timer = setTimeout(function() {
self._timer = null;
if (promiseComplete) { if (promiseComplete) {
return; return;
} }

Loading…
Cancel
Save