Skip to content

Instantly share code, notes, and snippets.

@somersbmatthews
Created January 22, 2021 16:55
Show Gist options
  • Select an option

  • Save somersbmatthews/16d407d10f160752c1df2eae6872b06a to your computer and use it in GitHub Desktop.

Select an option

Save somersbmatthews/16d407d10f160752c1df2eae6872b06a to your computer and use it in GitHub Desktop.
interrupt cancel #go #golang #context #signal #interrupt
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