Skip to content

Commit efd3071

Browse files
meixgjuanarbol
authored andcommitted
doc: fix question promise API example
PR-URL: #42465 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Mestery <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent b647336 commit efd3071

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

doc/api/readline.md

+5-8
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ added: v17.0.0
591591
prompt.
592592
* `options` {Object}
593593
* `signal` {AbortSignal} Optionally allows the `question()` to be canceled
594-
using an `AbortController`.
594+
using an `AbortSignal`.
595595
* Returns: {Promise} A promise that is fulfilled with the user's
596596
input in response to the `query`.
597597

@@ -612,20 +612,17 @@ const answer = await rl.question('What is your favorite food? ');
612612
console.log(`Oh, so your favorite food is ${answer}`);
613613
```
614614

615-
Using an `AbortController` to cancel a question.
615+
Using an `AbortSignal` to cancel a question.
616616

617617
```mjs
618-
const ac = new AbortController();
619-
const signal = ac.signal;
620-
621-
const answer = await rl.question('What is your favorite food? ', { signal });
622-
console.log(`Oh, so your favorite food is ${answer}`);
618+
const signal = AbortSignal.timeout(10_000);
623619

624620
signal.addEventListener('abort', () => {
625621
console.log('The food question timed out');
626622
}, { once: true });
627623

628-
setTimeout(() => ac.abort(), 10000);
624+
const answer = await rl.question('What is your favorite food? ', { signal });
625+
console.log(`Oh, so your favorite food is ${answer}`);
629626
```
630627

631628
### Class: `readlinePromises.Readline`

0 commit comments

Comments
 (0)