
About The Project
A simple object to manage graceful termination of your program. Works with context, and supports adding
termination tasks from multiple threads.
(back to top)
Getting Started
Installation
go get github.com/zrbecker/go-terminator
(back to top)
Usage
func main() {
ctx, t := terminator.WithTerminator(context.Background())
defer t.Terminate()
terminator.MustFromContext(ctx).AddTerminationTask(func() {
fmt.Println("Performing cleanup...")
})
fmt.Println("Application active. Press Ctrl+C to stop or wait 10 seconds for automatic shutdown.")
time.Sleep(10 * time.Second)
}
For more examples, please refer to the Examples
(back to top)
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
)
- Commit your Changes (
git commit -m 'Add some AmazingFeature'
)
- Push to the Branch (
git push origin feature/AmazingFeature
)
- Open a Pull Request
(back to top)
License
Distributed under the MIT License. See LICENSE.txt
for more information.
(back to top)
Zachary Becker - @zrbecker - zrbecker@gmail.com
Project Link: https://github.com/zrbecker/go-terminator
(back to top)