Documentation ¶
Overview ¶
Package cleanup provides a unified way to defer running functions until a later date.
Cleanup provides a way for tooling to defer running functions until a later date. A typical example would be wanting to defer running a shutdown function until main() exits:
func shutdown() { // shutdown function for some service that should really be run before the // program exits ... }
cleanup.Add(shutdown)
func main() { defer cleanup.Run() // Ensure that any cleanup functions are run on exit ... }
This work is licensed under CC0 1.0 Universal (CC0 1.0), Public Domain Dedication. For details see:
http://creativecommons.org/publicdomain/zero/1.0/ Online go-documentation is available at: https://godoc.org/bitbucket.org/pcas/tools/cleanup
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CancelOnSignal ¶
func CancelOnSignal(cancel context.CancelFunc, lg log.Interface)
CancelOnSignal installs a signal handler, calling the given cancel function on the first os.Interrupt. Subsequent os.Interrupt signals will cause immediate termination.
Types ¶
type Group ¶
type Group struct { Name string // The group's name // contains filtered or unexported fields }
Group is a collection of Runables that should be run together.
func (*Group) AddRunable ¶
AddRunable adds the given Runable to the group. This will panic if g is nil.
func (*Group) Run ¶
Run executes the Runables in the group, in LIFO order. Runables will be removed from the group as they are executed. It is safe for a Runable to add itself back to the group to be executed at a later date. The first error encountered (if any) will be returned, however all Runables will be run.