mage icon indicating copy to clipboard operation
mage copied to clipboard

How to run a cleanup function on control-c?

Open comicsads opened this issue 4 years ago • 1 comments

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!

comicsads avatar Sep 18 '19 22:09 comicsads

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.

natefinch avatar Sep 27 '19 18:09 natefinch