| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c6808f0 commit d335add
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -591,7 +591,7 @@ added: v17.0.0 | |||
| 591 | 591 | prompt. | |
| 592 | 592 | * `options` {Object} | |
| 593 | 593 | * `signal` {AbortSignal} Optionally allows the `question()` to be canceled | |
| 594 | - using an `AbortController`. | ||
| 594 | + using an `AbortSignal`. | ||
| 595 | 595 | * Returns: {Promise} A promise that is fulfilled with the user's | |
| 596 | 596 | input in response to the `query`. | |
| 597 | 597 | ||
@@ -612,20 +612,17 @@ const answer = await rl.question('What is your favorite food? '); | |||
| 612 | 612 | console.log(`Oh, so your favorite food is ${answer}`); | |
| 613 | 613 | ``` | |
| 614 | 614 | ||
| 615 | - Using an `AbortController` to cancel a question. | ||
| 615 | + Using an `AbortSignal` to cancel a question. | ||
| 616 | 616 | ||
| 617 | 617 | ```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); | ||
| 623 | 619 | ||
| 624 | 620 | signal.addEventListener('abort', () => { | |
| 625 | 621 | console.log('The food question timed out'); | |
| 626 | 622 | }, { once: true }); | |
| 627 | 623 | ||
| 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}`); | ||
| 629 | 626 | ``` | |
| 630 | 627 | ||
| 631 | 628 | ### Class: `readlinePromises.Readline` | |
| Back | FazBrowse Home | New Git URL |
0 commit comments