Created
January 22, 2021 16:55
-
-
Save somersbmatthews/16d407d10f160752c1df2eae6872b06a to your computer and use it in GitHub Desktop.
interrupt cancel #go #golang #context #signal #interrupt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| c := make(chan os.Signal) | |
| signal.Notify(c, os.Interrupt) | |
| go func() { | |
| select { | |
| case sig := <-c: | |
| fmt.Printf("Got %s signal. Aborting...\n", sig) | |
| os.Exit(1) | |
| } | |
| }() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment