atexit

package
v1.68.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2024 License: MIT Imports: 7 Imported by: 48

Documentation

Overview

Package atexit provides handling for functions you want called when the program exits unexpectedly due to a signal.

You should also make sure you call Run in the normal exit path.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IgnoreSignals

func IgnoreSignals()

IgnoreSignals disables the signal handler and prevents Run from being executed automatically

func OnError added in v1.53.0

func OnError(perr *error, fn func()) func()

OnError registers fn with atexit and returns a function which runs fn() if *perr != nil and deregisters fn

It should be used in a defer statement normally so

defer OnError(&err, cancelFunc)()

So cancelFunc will be run if the function exits with an error or at exit.

cancelFunc will only be run once.

func Run

func Run()

Run all the at exit functions if they haven't been run already

func Signalled added in v1.54.0

func Signalled() bool

Signalled returns true if an exit signal has been received

func Unregister

func Unregister(handle FnHandle)

Unregister a function using the handle returned by `Register`

Types

type FnHandle

type FnHandle *func()

FnHandle is the type of the handle returned by function `Register` that can be used to unregister an at-exit function

func Register

func Register(fn func()) FnHandle

Register a function to be called on exit. Returns a handle which can be used to unregister the function with `Unregister`.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL