Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
A Handler executes notification functions after a critical section (the function passed to its Run method), even in the presence of process termination via a termination signal. A final handler is executed if a termination signal is caught. The handler guarantees that the provided notify functions will be called at most once. A Handler is not reusable in the sense that its Run method should be called only once: calling it more times will not execute any of notify nor final functions.
func New ¶
New creates a new Handler. The final function will be called only if a termination signal is caught, after all notify functions are run. If final is nil, it defaults to os.Exit(2). The final function may call os.Exit if exiting is desired. The notify functions will be called when a termination signal is caught, or after the argument to the Run method completes.
func (*Handler) Run ¶
Run calls fn in the current goroutine, while waiting for a termination signal in a separate goroutine. If a signal is caught while this method is running, the notify functions will be called sequentially in order, and then the final function is called. Otherwise, only the notify functions are called after fn returns. The fn function may not complete, for example in case of a call to os.Exit.