Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
doc: fix question promise API example
using AbortSignal.timeout
  • Loading branch information
meixg committed Mar 28, 2022
commit 5ec520e7c44b367ea28a82f0087e510089482542
9 changes: 3 additions & 6 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,18 +612,15 @@ 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 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}`);
```
Expand Down