Browse Source

repl: event ordering: delay 'close' until 'flushHistory'

Emitting 'close' before the history has flushed is somewhat incorrect
and rather confusing.

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

Refs: https://github.com/nodejs/node/pull/2356
PR-URL: https://github.com/nodejs/node/pull/3435
Reviewed By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
v5.x
Jeremiah Senkpiel 9 years ago
committed by Rod Vagg
parent
commit
ce391ed849
  1. 20
      lib/repl.js

20
lib/repl.js

@ -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');
@ -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,
@ -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');
@ -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) {

Loading…
Cancel
Save