clear response listeners after 2 seconds.

This commit is contained in:
Christopher Jeffrey 2015-02-07 00:15:25 -08:00
parent d70fa6d4a2
commit 0290d7f15f
1 changed files with 8 additions and 1 deletions

View File

@ -1383,13 +1383,20 @@ Program.prototype.response = function(name, text, callback) {
? 'response ' + name
: 'response';
this.once(name, function(event) {
var onresponse;
this.once(name, onresponse = function(event) {
if (timeout) clearTimeout(timeout);
if (event.type === 'error') {
return callback(new Error(event.event + ': ' + event.text));
}
return callback(null, event);
});
var timeout = setTimeout(function() {
self.removeListener(name, onresponse);
}, 2000);
return this._write(text);
};