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

How to run a cleanup function on control-c? #266

Open
comicsads opened this issue Sep 18, 2019 · 1 comment
Open

How to run a cleanup function on control-c? #266

comicsads opened this issue Sep 18, 2019 · 1 comment

Comments

@comicsads
Copy link

I would like to run a target/function when another target gets closed using ctrl-c. The reason for this is I'm creating a webserver using go, and have a mage target to build an executable and run it, and the only way to close it is by using ctrl-c. I would like to be able to run the target Cleanup() after hitting ctrl-c.
Is there anyway to do this? Is this what context.Context() is for?
Thanks in advance!

@natefinch
Copy link
Member

Hmm yeah, that's a feature I intended to implement with the context, but currently it's not implemented. What should happen is that ctrl-c should cancel the context and then exit after a short wait.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants