You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
393 B
28 lines
393 B
// +build !plan9
|
|
|
|
package main
|
|
|
|
import (
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
)
|
|
|
|
func OnInterrupt(fn func()) {
|
|
// deal with control+c,etc
|
|
signalChan := make(chan os.Signal, 1)
|
|
signal.Notify(signalChan,
|
|
os.Interrupt,
|
|
os.Kill,
|
|
syscall.SIGALRM,
|
|
syscall.SIGHUP,
|
|
syscall.SIGINT,
|
|
syscall.SIGTERM,
|
|
syscall.SIGQUIT)
|
|
go func() {
|
|
for _ = range signalChan {
|
|
fn()
|
|
os.Exit(0)
|
|
}
|
|
}()
|
|
}
|