Last active
October 12, 2021 20:06
-
-
Save hinst/90b54ec94e5765ef19b4 to your computer and use it in GitHub Desktop.
Signal receiver for Go
This file contains 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
package main | |
import ( | |
"os" | |
"os/signal" | |
"syscall" | |
) | |
func InstallShutdownReceiver(receiver func()) { | |
c := make(chan os.Signal, 1) | |
signal.Notify(c, syscall.SIGINT) | |
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