Documentation ¶
Overview ¶
Package atexit provides functionality similar to the C standard library's atexit() call.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // RecoveryHandler will be used to capture any panics caused by functions that have been installed when run during // exit. It may be set to nil to silently ignore them. RecoveryHandler errs.RecoveryHandler = func(err error) { errs.Log(err) } )
Functions ¶
func Exit ¶
func Exit(status int)
Exit runs any registered exit functions in the inverse order they were registered and then exits the progream with the specified status. If a previous call to Exit() is already being handled, this method does nothing but does not return. Recursive calls to Exit() will trigger a panic, which the exit handling will catch and report, but will then proceed with exit as normal. Note that once Exit() is called, no subsequent changes to the registered list of functions will have an effect (i.e. you cannot Unregister() a function inside an exit handler to prevent its execution, nor can you Register() a new function).
func Register ¶
func Register(f func()) int
Register a function to be run at exit. Returns an ID that can be used to remove the function later, if desired. Registering a function after Exit() has been called (i.e. in a function that was registered) will have no effect.
func Unregister ¶ added in v1.25.0
func Unregister(id int)
Unregister a function that was previously registered to be run at exit. If the ID is no longer present, nothing happens. Unregistering a function after Exit() has been called (i.e. in a function that was registered) will have no effect.
Types ¶
This section is empty.