Discover Packages
github.com/tebeka/atexit
package
module
Version:
v0.3.0
Opens a new window with list of versions in this module.
Published: Feb 22, 2020
License: MIT
Opens a new window with license information.
Imports: 4
Opens a new window with list of imports.
Imported by: 46 modules, 116 packages
The first number is the count of modules that contain a package that imports this one.
The module count is a better indicator of popularity than the package count.
A module with 100 importing packages is counted only once instead of 100 times,
reflecting the fact that the choice to use the package was likely made only once,
not 100 times.
A '?' means that the value hasn't been computed yet.
Opens a new window with list of known importers.
README
README
¶
About
Simple atexit implementation for Go .
Note that you have to call atexit.Exit and not os.Exit to terminate your
program (that is, if you want the atexit handlers to execute).
Example usage
package main
import (
"fmt"
"github.com/tebeka/atexit"
)
func handler() {
fmt.Println("Exiting")
}
func main() {
atexit.Register(handler)
atexit.Exit(0)
}
Install
go get github.com/tebeka/atexit
Expand ▾
Collapse ▴
Documentation
¶
Package atexit lets you define handlers when the program exits.
Add handlers using Register.
You must call atexit.Exit to get the handler invoked (and then terminate the program).
This package also provides replacements to log.Fatal, log.Fatalf and log.Fatalln.
Example:
package main
import (
"fmt"
"github.com/tebeka/atexit"
)
func handler() {
fmt.Println("Exiting")
}
func main() {
atexit.Register(handler)
atexit.Exit(0)
}
Exit runs all the atexit handlers and then terminates the program using
os.Exit(code)
func Fatal(v ...interface{})
Fatal runs all the atexit handler then calls log.Fatal (which will terminate
the program)
func Fatalf(format string , v ...interface{})
Fatalf runs all the atexit handler then calls log.Fatalf (which will
terminate the program)
func Fatalln(v ...interface{})
Fatalln runs all the atexit handler then calls log.Fatalln (which will
terminate the program)
type HandlerID ¶
added in
v0.3.0
Register adds a handler, call atexit.Exit to invoke all handlers.
func (HandlerID) Cancel ¶
added in
v0.3.0
Cancel cancels the handler associated with id
Source Files
¶
Click to show internal directories.
Click to hide internal directories.