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

[Question] Are spinner task groups no longer supported? #157

Closed
zateutsch opened this issue Aug 31, 2023 · 6 comments
Closed

[Question] Are spinner task groups no longer supported? #157

zateutsch opened this issue Aug 31, 2023 · 6 comments

Comments

@zateutsch
Copy link

Can't find this from the readme on the latest version of prompts.

image

@zateutsch zateutsch changed the title Are spinner task groups no longer supported? [Question] Are spinner task groups no longer supported? Aug 31, 2023
@orochaa
Copy link
Contributor

orochaa commented Aug 31, 2023

@zateutsch It is going to be available on next release, for now you can use spinner individually

@cpreston321
Copy link
Collaborator

Hello @zateutsch 👋🏼

This is currently staged for release #149. This feature is somewhat new and is tied #152 but doesn't solve the issue completely. So I am waiting on a response from him. I also wanted to crunch some other bugs before the next release.

Thanks,
CP 🚀

@zateutsch
Copy link
Author

@cpreston321 @Mist3rBru Thanks for the speedy answer.

As a follow up, is there any way to listen for a cancel during a spinner as it is currently implemented?

@orochaa
Copy link
Contributor

orochaa commented Aug 31, 2023

@zateutsch the spinner has a built in hook that handle this, but if you want to, you can try something like this:

const s = p.spinner()
s.start('First message')
// do stuff...
process.on('exit', () => {
  // handle cancel...
  s.stop('Last message')
  process.exit(0)
})

@zateutsch
Copy link
Author

Thanks for the answers. Closing as resolved.

@mikenikles
Copy link

mikenikles commented Sep 19, 2023

FWIW, I learned this leads to a Node.js memory leak warning once you stop 11 spinners (yes, I have a rather complex CLI 😅).

I ended up with the following helpers to avoid the warning:

function exitProcess() {
  process.stdout.write("\n");
  process.exit(1);
}

/**
 * @see https://github.com/natemoo-re/clack/issues/134#issuecomment-1694564106
 */
export function stopSpinner(s: ReturnType<typeof spinner>, message: string) {
  s.stop(message);
  process.removeListener("SIGINT", exitProcess);
  process.on("SIGINT", exitProcess);
}

Update: Just as I posted that, I realized we could just use process.once('exit', ...) and avoid all the helpers I posted above. I haven't tested, but if I understand once correctly, it achieves the same as the helpers above.

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

No branches or pull requests

4 participants