terminator

package module
v0.0.0-...-8e19696 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2024 License: MIT Imports: 5 Imported by: 0

README

Contributors Forks Stargazers Issues MIT License LinkedIn


go-terminator

Handle graceful termination of your program
Report Bug · Request Feature

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!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Zachary Becker - @zrbecker - zrbecker@gmail.com

Project Link: https://github.com/zrbecker/go-terminator

(back to top)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Terminator

type Terminator interface {
	AddTerminationTask(task func())
	Terminate()
}

func FromContext

func FromContext(ctx context.Context) (Terminator, bool)

func MustFromContext

func MustFromContext(ctx context.Context) Terminator

func WithTerminator

func WithTerminator(ctx context.Context) (context.Context, Terminator)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL