Documentation ¶
Overview ¶
Package graceful contains API for working with graceful application shutdown.
Application starts listening for SIGINT or SIGTERM signals and handles them properly.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrTimeoutExceeded is returned when the application fails to shutdown for a given period of time. ErrTimeoutExceeded = errors.New("failed to perform graceful shutdown: timeout exceeded") // ErrForceShutdown is returned when the user or operating system is sending SIGINT or SIGTERM // for the application being is graceful-shutdown state. ErrForceShutdown = errors.New("failed to perform graceful shutdown: force shutdown occurred") )
Functions ¶
func AddCallback ¶
func AddCallback(fn ShutdownFunc)
AddCallback registers a callback for execution before shutdown.
func ExecOnError ¶
func ExecOnError(cb func(err error))
ExecOnError executes the given handler when shutdown callback returns any error.
func IsShuttingDown ¶
func IsShuttingDown() bool
func WaitShutdown ¶
func WaitShutdown() error
WaitShutdown waits for application shutdown.
If the user or operating system interrupts the graceful shutdown, ErrForceShutdown is returned. If applications fails to shutdown for a given period of time, ErrTimeoutExceeded is returned.
Types ¶
type ShutdownFunc ¶
type ShutdownFunc func() error
ShutdownFunc is a callback-type for registering callbacks before application shutdown.
Click to show internal directories.
Click to hide internal directories.