Skip to content

Commit

Permalink
repl: event ordering: delay 'close' until 'flushHistory'
Browse files Browse the repository at this point in the history
Emitting 'close' before the history has flushed is somewhat incorrect
and rather confusing.

This also makes the 'close' event always asynchronous for consistency.

Refs: #2356
PR-URL: #3435
Reviewed By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
  • Loading branch information
Fishrock123 committed Oct 22, 2015
1 parent f5445db commit ecab7a6
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const Stream = require('stream');
const vm = require('vm');
const path = require('path');
const fs = require('fs');
const rl = require('readline');
const Interface = require('readline').Interface;
const Console = require('console').Console;
const domain = require('domain');
const debug = util.debuglog('repl');
Expand Down Expand Up @@ -229,7 +229,7 @@ function REPLServer(prompt,
self.complete(text, callback);
}

rl.Interface.call(this, {
Interface.call(this, {
input: self.inputStream,
output: self.outputStream,
completer: complete,
Expand Down Expand Up @@ -453,7 +453,7 @@ function REPLServer(prompt,

self.displayPrompt();
}
inherits(REPLServer, rl.Interface);
inherits(REPLServer, Interface);
exports.REPLServer = REPLServer;

exports.REPL_MODE_SLOPPY = Symbol('repl-sloppy');
Expand All @@ -479,6 +479,20 @@ exports.start = function(prompt,
return repl;
};

REPLServer.prototype.close = function replClose() {
if (this.terminal && this._flushing && !this._closingOnFlush) {
this._closingOnFlush = true;
this.once('flushHistory', () =>
Interface.prototype.close.call(this)
);

return;
}
process.nextTick(() =>
Interface.prototype.close.call(this)
);
};

REPLServer.prototype.createContext = function() {
var context;
if (this.useGlobal) {
Expand Down

0 comments on commit ecab7a6

Please sign in to comment.