Skip to content

Commit

Permalink
doc: fix question promise API example
Browse files Browse the repository at this point in the history
PR-URL: #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>
  • Loading branch information
meixg authored and juanarbol committed Apr 6, 2022
1 parent c6808f0 commit d335add
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions doc/api/readline.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand All @@ -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`
Expand Down

0 comments on commit d335add

Please sign in to comment.