From 61dfc5d02b56268036b68d3a52423bf3e00316e0 Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Sat, 19 Jun 2021 08:49:30 +0200 Subject: [PATCH] Add example code --- README.md | 4 +++- example/example.go | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 example/example.go 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() + +}