diff --git a/README.md b/README.md index 68d4be8..01e2f81 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,6 @@ A simple library for graceful shutdowns -100% covered with unit tests. \ No newline at end of file +100% covered with unit tests. + +See and try the example in `/example` to see the how things should be done. \ No newline at end of file diff --git a/example/example.go b/example/example.go new file mode 100644 index 0000000..e4fce24 --- /dev/null +++ b/example/example.go @@ -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() + +}