Permalink
Browse files

use a queue for incoming lines, passes all the tests again

  • Loading branch information...
1 parent dc53789 commit 14d461b7e62005c8073f6f4e3141d04ed499475a @substack committed Aug 8, 2013
Showing with 10 additions and 3 deletions.
  1. +10 −3 index.js
View
@@ -268,6 +268,7 @@ Bash.prototype.createStream = function () {
var current = null;
self.once('exit', end);
+ var queue = [];
input.pipe(through(write, end));
return duplexer(input, output);
@@ -279,6 +280,7 @@ Bash.prototype.createStream = function () {
}
return;
}
+ if (current) return queue.push(line);
var p = self.eval(line);
p.on('SIGALRM', exit('SIGALRM', 142, 'Alarm clock'));
@@ -314,20 +316,25 @@ Bash.prototype.createStream = function () {
current = null;
nextTick(function () {
if (!closed) output.queue(self.getPrompt());
+ if (queue.length) {
+ write(queue.shift());
+ }
+ else if (closed) {
+ output.queue(null);
+ self.emit('exit', 0);
+ }
});
});
p.pipe(output, { end: false });
p.resume();
}
function end () {
- if (closed) return;
+ closed = true;
if (!current) {
- closed = true;
output.queue(null);
self.emit('exit', 0);
}
- else current.on('exit', end);
}
};

0 comments on commit 14d461b

Please sign in to comment.