diff options
author | Xuguang Mei <meixg@foxmail.com> | 2022-03-28 13:44:21 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-28 13:44:21 +0300 |
commit | 8a96ff7e545041dbf08483b4d512eefb488f0479 (patch) | |
tree | 78c3c379661b9f90f6f1b124bf554f6b6c6cb49a /doc/api/readline.md | |
parent | 2e6d5e111c9c42a6f1866b64c131332f4c819d57 (diff) |
doc: fix question promise API example
PR-URL: https://github.com/nodejs/node/pull/42465
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Mestery <mestery@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'doc/api/readline.md')
-rw-r--r-- | doc/api/readline.md | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/doc/api/readline.md b/doc/api/readline.md index 724fbc6be99..328af419d87 100644 --- a/doc/api/readline.md +++ b/doc/api/readline.md @@ -591,7 +591,7 @@ added: v17.0.0 prompt. * `options` {Object} * `signal` {AbortSignal} Optionally allows the `question()` to be canceled - using an `AbortController`. + using an `AbortSignal`. * Returns: {Promise} A promise that is fulfilled with the user's input in response to the `query`. @@ -612,20 +612,17 @@ const answer = await rl.question('What is your favorite food? '); console.log(`Oh, so your favorite food is ${answer}`); ``` -Using an `AbortController` to cancel a question. +Using an `AbortSignal` to cancel a question. ```mjs -const ac = new AbortController(); -const signal = ac.signal; - -const answer = await rl.question('What is your favorite food? ', { signal }); -console.log(`Oh, so your favorite food is ${answer}`); +const signal = AbortSignal.timeout(10_000); signal.addEventListener('abort', () => { console.log('The food question timed out'); }, { once: true }); -setTimeout(() => ac.abort(), 10000); +const answer = await rl.question('What is your favorite food? ', { signal }); +console.log(`Oh, so your favorite food is ${answer}`); ``` ### Class: `readlinePromises.Readline` |