Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add abort controller #216

Merged

Conversation

jacobparis
Copy link
Contributor

@jacobparis jacobparis commented Dec 17, 2024

This PR adds support for an abort controller to the base Prompts class

This allows folks to programmatically cancel prompts after they've started, like with a timeout

const shouldContinue = await confirm({
  message: 'This message will self destruct in 5 seconds',
  signal: AbortSignal.timeout(3000),
});

or maybe you have a long automated process to get an answer but the user can cut in with their answer at any time, and, once one answer is picked we should cancel the other process

const abortController = new AbortController()

const projectType = await Promise.race([
  detectSystemSettings({
    signal: abortController.signal
  }),
  select({
    message: 'Pick a project type.',
    options: [
      { value: 'ts', label: 'TypeScript' },
      { value: 'js', label: 'JavaScript' },
      { value: 'coffee', label: 'CoffeeScript', hint: 'oh no'},
    ],
     signal: abortController.signal,
  });
  
abortController.abort()

Lots of opportunity here, abort controllers are amazing

Copy link

changeset-bot bot commented Dec 17, 2024

🦋 Changeset detected

Latest commit: 8214d75

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@clack/core Minor
@clack/prompts Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

packages/core/src/prompts/prompt.ts Outdated Show resolved Hide resolved
@natemoo-re natemoo-re merged commit 801246b into bombshell-dev:main Dec 19, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants