mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
readline: fix pre-aborted signal question handling
fix pre-aborted question handling PR-URL: https://github.com/nodejs/node/pull/37929 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
54c525ef0e
commit
dbab2893ef
2 changed files with 34 additions and 0 deletions
|
@ -59,6 +59,7 @@ const {
|
|||
StringPrototypeStartsWith,
|
||||
StringPrototypeTrim,
|
||||
Promise,
|
||||
PromiseReject,
|
||||
Symbol,
|
||||
SymbolAsyncIterator,
|
||||
SafeStringIterator,
|
||||
|
@ -393,6 +394,10 @@ Interface.prototype.question = function(query, options, cb) {
|
|||
options = typeof options === 'object' && options !== null ? options : {};
|
||||
|
||||
if (options.signal) {
|
||||
if (options.signal.aborted) {
|
||||
return;
|
||||
}
|
||||
|
||||
options.signal.addEventListener('abort', () => {
|
||||
this[kQuestionCancel]();
|
||||
}, { once: true });
|
||||
|
@ -413,6 +418,10 @@ Interface.prototype.question = function(query, options, cb) {
|
|||
Interface.prototype.question[promisify.custom] = function(query, options) {
|
||||
options = typeof options === 'object' && options !== null ? options : {};
|
||||
|
||||
if (options.signal && options.signal.aborted) {
|
||||
return PromiseReject(new AbortError());
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.question(query, options, resolve);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue