Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ce391ed

Browse filesBrowse files
Fishrock123rvagg
authored andcommitted
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: #2356 PR-URL: #3435 Reviewed By: Evan Lucas <evanlucas@me.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
1 parent b4f4c24 commit ce391ed
Copy full SHA for ce391ed

File tree

Expand file treeCollapse file tree

1 file changed

+17
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+17
-3
lines changed
Open diff view settings
Collapse file

‎lib/repl.js‎

Copy file name to clipboardExpand all lines: lib/repl.js
+17-3Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const Stream = require('stream');
2727
const vm = require('vm');
2828
const path = require('path');
2929
const fs = require('fs');
30-
const rl = require('readline');
30+
const Interface = require('readline').Interface;
3131
const Console = require('console').Console;
3232
const domain = require('domain');
3333
const debug = util.debuglog('repl');
@@ -229,7 +229,7 @@ function REPLServer(prompt,
229229
self.complete(text, callback);
230230
}
231231

232-
rl.Interface.call(this, {
232+
Interface.call(this, {
233233
input: self.inputStream,
234234
output: self.outputStream,
235235
completer: complete,
@@ -453,7 +453,7 @@ function REPLServer(prompt,
453453

454454
self.displayPrompt();
455455
}
456-
inherits(REPLServer, rl.Interface);
456+
inherits(REPLServer, Interface);
457457
exports.REPLServer = REPLServer;
458458

459459
exports.REPL_MODE_SLOPPY = Symbol('repl-sloppy');
@@ -479,6 +479,20 @@ exports.start = function(prompt,
479479
return repl;
480480
};
481481

482+
REPLServer.prototype.close = function replClose() {
483+
if (this.terminal && this._flushing && !this._closingOnFlush) {
484+
this._closingOnFlush = true;
485+
this.once('flushHistory', () =>
486+
Interface.prototype.close.call(this)
487+
);
488+
489+
return;
490+
}
491+
process.nextTick(() =>
492+
Interface.prototype.close.call(this)
493+
);
494+
};
495+
482496
REPLServer.prototype.createContext = function() {
483497
var context;
484498
if (this.useGlobal) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.