Simplify SIGINT handling code. NFC

This commit is contained in:
Catherine
2025-11-23 03:03:04 +00:00
parent fa02595f8b
commit d82ae69625
3 changed files with 9 additions and 13 deletions

View File

@@ -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")
}
}

View File

@@ -6,6 +6,8 @@ func OnReload(handler func()) {
// not implemented
}
func OnInterrupt(handler func()) {
// not implemented
func WaitForInterrupt() {
for {
// Ctrl+C not supported
}
}

View File

@@ -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)
}