Skip to content

Commit

Permalink
Chore: Review README timeout code
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed Mar 21, 2024
1 parent ff540a9 commit 4cea973
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/demo/demos/timeout.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async function demo() {
.finally(() => {
ac.abort();
})
// Silencing the cancelation error.
// Silencing the cancellation error.
.catch(() => {});

const defaultValue = setTimeout(5000, 'timeout', { signal: ac.signal }).then(() => {
Expand Down
27 changes: 14 additions & 13 deletions packages/prompts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,23 @@ import { setTimeout } from 'node:timers/promises';
import { input } from '@inquirer/prompts';

const ac = new AbortController();
const {signal} = ac;
const prompt = input(...);
const prompt = input({
message: 'Enter a value (timing out in 5 seconds)',
});

let answer;

setTimeout(5000, 'timeout', {signal})
.catch(() => {})
.then(() => {
prompt.cancel();
answer = defaultValue;
prompt
.finally(() => {
ac.abort();
})
// Silencing the cancellation error.
.catch(() => {});

const defaultValue = setTimeout(5000, 'timeout', { signal: ac.signal }).then(() => {
prompt.cancel();
return 'Timed out!';
});

await prompt.then((value) => {
ac.abort()
answer = value
})
const answer = await Promise.race([defaultValue, prompt]);
```

## Using as pre-commit/git hooks, or scripts
Expand Down

0 comments on commit 4cea973

Please sign in to comment.