1
Fork 0

Add example code

This commit is contained in:
Jan-Lukas Else 2021-06-19 08:49:30 +02:00
parent 5da0055618
commit 61dfc5d02b
2 changed files with 29 additions and 1 deletions

View File

@ -2,4 +2,6 @@
A simple library for graceful shutdowns
100% covered with unit tests.
100% covered with unit tests.
See and try the example in `/example` to see the how things should be done.

26
example/example.go Normal file
View File

@ -0,0 +1,26 @@
package main
import (
"log"
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() {
log.Println("Shutdown")
})
log.Println("Started")
// CTRL + C or otherwise interrupt the program
// Wait for shutdowner to finish
sd.Wait()
}