shutdown

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHandler

func AddHandler(handler Handler)

func Context added in v0.7.0

func Context() context.Context

func Exit added in v0.7.0

func Exit(reason string)

func NewContext added in v0.8.0

func NewContext() (context.Context, error)

NewContext creates a root, shutdown-aware context for the entire program.

In any Go application, the root context serves as the base for all other derived contexts. It is typically used to propagate cancellation signals and deadlines across multiple goroutines and services. `NewContext` ensures that the root context is properly initialized and protected from multiple concurrent creations.

This function wraps `WithContext(context.Background())` and returns a cancelable context that will be automatically canceled when the application initiates a shutdown, either manually via `Shutdown()`/`Exit()` or due to system signals (e.g., SIGINT, SIGTERM). Using this root context as the base for all other contexts ensures consistent handling of shutdown across the program.

Example usage:

ctx, err := shutdown.NewContext()
if err != nil {
    panic(err)
}
// pass `ctx` to servers, workers, or any long-running routines

By standardizing the creation of a root shutdown context, the application can gracefully cancel all operations and clean up resources consistently when shutting down.

func Shutdown

func Shutdown(reason string)

func Wait

func Wait() string

func WithContext added in v0.7.0

func WithContext(parent context.Context) (context.Context, error)

Types

type Handler added in v0.4.0

type Handler func(ctx context.Context, reason string) error

Jump to

Keyboard shortcuts

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