summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/internal/repl/history.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/internal/repl/history.js b/lib/internal/repl/history.js
index dd3ea85095..5d90b40e00 100644
--- a/lib/internal/repl/history.js
+++ b/lib/internal/repl/history.js
@@ -93,6 +93,7 @@ function setupHistory(repl, historyPath, ready) {
fs.ftruncate(hnd, 0, (err) => {
repl._historyHandle = hnd;
repl.on('line', online);
+ repl.once('exit', onexit);
// Reading the file data out erases it
repl.once('flushHistory', function() {
@@ -137,6 +138,15 @@ function setupHistory(repl, historyPath, ready) {
}
}
}
+
+ function onexit() {
+ if (repl._flushing) {
+ repl.once('flushHistory', onexit);
+ return;
+ }
+ repl.off('line', online);
+ fs.close(repl._historyHandle, () => {});
+ }
}
function _replHistoryMessage() {