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 <[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]>
  • Loading branch information
meixg authored and juanarbol committed Apr 4, 2022
1 parent b647336 commit efd3071
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 efd3071

Please sign in to comment.