1
Fork 0
go-shutdowner/example/example.go

30 lines
490 B
Go

package main
import (
"log"
"time"
goshutdowner "git.jlel.se/jlelse/go-shutdowner"
)
func main() {
// Declare shutdowner
var sd goshutdowner.Shutdowner
// Add a function to execute on shutdown
sd.Add(func() {
time.Sleep(5 * time.Second)
log.Println("Shutdown")
})
log.Println("Started")
log.Println("Print CTRL + C once to gracefully shutdown, twice to cancel execution")
// CTRL + C or otherwise interrupt the program
// Wait for shutdowner to finish
sd.Wait()
}