mirror of
https://codeberg.org/git-pages/git-pages.git
synced 2026-05-14 03:01:48 +00:00
Simplify SIGINT handling code. NFC
This commit is contained in:
@@ -385,10 +385,7 @@ func Main() {
|
||||
log.Println("serve: ready")
|
||||
}
|
||||
|
||||
interrupt := make(chan struct{})
|
||||
OnInterrupt(func() { interrupt <- struct{}{} })
|
||||
<-interrupt
|
||||
|
||||
log.Println("exiting gracefully")
|
||||
WaitForInterrupt()
|
||||
log.Println("serve: exiting")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ func OnReload(handler func()) {
|
||||
// not implemented
|
||||
}
|
||||
|
||||
func OnInterrupt(handler func()) {
|
||||
// not implemented
|
||||
func WaitForInterrupt() {
|
||||
for {
|
||||
// Ctrl+C not supported
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,9 @@ func OnReload(handler func()) {
|
||||
}()
|
||||
}
|
||||
|
||||
func OnInterrupt(handler func()) {
|
||||
func WaitForInterrupt() {
|
||||
sigint := make(chan os.Signal, 1)
|
||||
signal.Notify(sigint, syscall.SIGINT)
|
||||
go func() {
|
||||
<-sigint
|
||||
signal.Stop(sigint)
|
||||
handler()
|
||||
}()
|
||||
<-sigint
|
||||
signal.Stop(sigint)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user