Skip to content

Instantly share code, notes, and snippets.

@hinst
Last active May 14, 2017 12:27
Show Gist options
  • Save hinst/ed34e7fc8b63879416dc9d4b6fa2f8e3 to your computer and use it in GitHub Desktop.
Save hinst/ed34e7fc8b63879416dc9d4b6fa2f8e3 to your computer and use it in GitHub Desktop.
package ho
import (
"os"
"os/signal"
"syscall"
)
func InstallShutdownReceiver(receiver func()) {
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt)
signal.Notify(c, os.Kill)
signal.Notify(c, syscall.SIGTERM)
go func() {
for currentSignal := range c {
var _ = currentSignal
receiver()
}
}()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment