Skip to content

Commit

Permalink
readline: use internal addAbortListener
Browse files Browse the repository at this point in the history
PR-URL: #52081
Refs: #48596
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
atlowChemi authored and marco-ippolito committed May 3, 2024
1 parent 37abad8 commit fb601c3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/internal/readline/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const {
stripVTControlCharacters,
} = require('internal/util/inspect');
const EventEmitter = require('events');
const { addAbortListener } = require('internal/events/abort_listener');
const {
charLengthAt,
charLengthLeft,
Expand Down Expand Up @@ -326,7 +327,7 @@ function InterfaceConstructor(input, output, completer, terminal) {
if (signal.aborted) {
process.nextTick(onAborted);
} else {
const disposable = EventEmitter.addAbortListener(signal, onAborted);
const disposable = addAbortListener(signal, onAborted);
self.once('close', disposable[SymbolDispose]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Interface.prototype.question = function question(query, options, cb) {
const onAbort = () => {
this[kQuestionCancel]();
};
addAbortListener ??= require('events').addAbortListener;
addAbortListener ??= require('internal/events/abort_listener').addAbortListener;
const disposable = addAbortListener(options.signal, onAbort);
const originalCb = cb;
cb = typeof cb === 'function' ? (answer) => {
Expand Down Expand Up @@ -175,7 +175,7 @@ Interface.prototype.question[promisify.custom] = function question(query, option
const onAbort = () => {
reject(new AbortError(undefined, { cause: options.signal.reason }));
};
addAbortListener ??= require('events').addAbortListener;
addAbortListener ??= require('internal/events/abort_listener').addAbortListener;
const disposable = addAbortListener(options.signal, onAbort);
cb = (answer) => {
disposable[SymbolDispose]();
Expand Down
2 changes: 1 addition & 1 deletion lib/readline/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Interface extends _Interface {
this[kQuestionCancel]();
reject(new AbortError(undefined, { cause: options.signal.reason }));
};
addAbortListener ??= require('events').addAbortListener;
addAbortListener ??= require('internal/events/abort_listener').addAbortListener;
const disposable = addAbortListener(options.signal, onAbort);

cb = (answer) => {
Expand Down

0 comments on commit fb601c3

Please sign in to comment.