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

30 lines
490 B
Go
Raw Normal View History

2021-06-19 06:49:30 +00:00
package main
import (
"log"
2021-06-19 21:18:56 +00:00
"time"
2021-06-19 06:49:30 +00:00
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() {
2021-06-19 21:18:56 +00:00
time.Sleep(5 * time.Second)
2021-06-19 06:49:30 +00:00
log.Println("Shutdown")
})
log.Println("Started")
2021-06-19 21:18:56 +00:00
log.Println("Print CTRL + C once to gracefully shutdown, twice to cancel execution")
2021-06-19 06:49:30 +00:00
// CTRL + C or otherwise interrupt the program
// Wait for shutdowner to finish
sd.Wait()
}