GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — readline: fix question stack overflow · nodejs/node@7e8a00a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • readline.js
  • test/parallel
    • test-readline-interface.js
    • test-readline-promises-interface.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/readline.js‎

Copy file name to clipboardExpand all lines: lib/readline.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,10 @@ Interface.prototype.question = function(query, options, cb) {
148148
const cleanup = () => {
149149
options.signal.removeEventListener(onAbort);
150150
};
151+
const originalCb = cb;
151152
cb = typeof cb === 'function' ? (answer) => {
152153
cleanup();
153-
return cb(answer);
154+
return originalCb(answer);
154155
} : cleanup;
155156
}
156157

Collapse file

‎test/parallel/test-readline-interface.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-readline-interface.js
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,17 @@ for (let i = 0; i < 12; i++) {
10061006
rli.close();
10071007
}
10081008

1009+
// Calling the question callback with abort signal
1010+
{
1011+
const [rli] = getInterface({ terminal });
1012+
const { signal } = new AbortController();
1013+
rli.question('foo?', { signal }, common.mustCall((answer) => {
1014+
assert.strictEqual(answer, 'bar');
1015+
}));
1016+
rli.write('bar\n');
1017+
rli.close();
1018+
}
1019+
10091020
// Calling the question multiple times
10101021
{
10111022
const [rli] = getInterface({ terminal });
@@ -1030,6 +1041,19 @@ for (let i = 0; i < 12; i++) {
10301041
rli.close();
10311042
}
10321043

1044+
// Calling the promisified question with abort signal
1045+
{
1046+
const [rli] = getInterface({ terminal });
1047+
const question = util.promisify(rli.question).bind(rli);
1048+
const { signal } = new AbortController();
1049+
question('foo?', { signal })
1050+
.then(common.mustCall((answer) => {
1051+
assert.strictEqual(answer, 'bar');
1052+
}));
1053+
rli.write('bar\n');
1054+
rli.close();
1055+
}
1056+
10331057
// Aborting a question
10341058
{
10351059
const ac = new AbortController();
Collapse file

‎test/parallel/test-readline-promises-interface.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-readline-promises-interface.js
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,17 @@ for (let i = 0; i < 12; i++) {
909909
rli.close();
910910
}
911911

912+
// Calling the question callback with abort signal
913+
{
914+
const [rli] = getInterface({ terminal });
915+
const { signal } = new AbortController();
916+
rli.question('foo?', { signal }).then(common.mustCall((answer) => {
917+
assert.strictEqual(answer, 'bar');
918+
}));
919+
rli.write('bar\n');
920+
rli.close();
921+
}
922+
912923
// Aborting a question
913924
{
914925
const ac = new AbortController();

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.