var terminationSignals … type Handler … // New creates a new handler that guarantees all notify functions are run after the critical // section exits (or is interrupted by the OS), then invokes the final handler. If no final // handler is specified, the default final is `os.Exit(1)`. A handler can only be used for // one critical section. func New(final func(os.Signal), notify ...func()) *Handler { … } // Close executes all the notification handlers if they have not yet been executed. func (h *Handler) Close() { … } // Signal is called when an os.Signal is received, and guarantees that all notifications // are executed, then the final handler is executed. This function should only be called once // per Handler instance. func (h *Handler) Signal(s os.Signal) { … } // Run ensures that any notifications are invoked after the provided fn exits (even if the // process is interrupted by an OS termination signal). Notifications are only invoked once // per Handler instance, so calling Run more than once will not behave as the user expects. func (h *Handler) Run(fn func() error) error { … }