From 0290d7f15ffc0e10133a3bb74f36594f5183ce9b Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sat, 7 Feb 2015 00:15:25 -0800 Subject: [PATCH] clear response listeners after 2 seconds. --- lib/program.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/program.js b/lib/program.js index d7c6d9b..99d4434 100644 --- a/lib/program.js +++ b/lib/program.js @@ -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); };