mirror of https://github.com/junegunn/fzf
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
554 B
Go
29 lines
554 B
Go
package util
|
|
|
|
import (
|
|
"sync"
|
|
)
|
|
|
|
var atExitFuncs []func()
|
|
|
|
// AtExit registers the function fn to be called on program termination.
|
|
// The functions will be called in reverse order they were registered.
|
|
func AtExit(fn func()) {
|
|
if fn == nil {
|
|
panic("AtExit called with nil func")
|
|
}
|
|
once := &sync.Once{}
|
|
atExitFuncs = append(atExitFuncs, func() {
|
|
once.Do(fn)
|
|
})
|
|
}
|
|
|
|
// RunAtExitFuncs runs any functions registered with AtExit().
|
|
func RunAtExitFuncs() {
|
|
fns := atExitFuncs
|
|
for i := len(fns) - 1; i >= 0; i-- {
|
|
fns[i]()
|
|
}
|
|
atExitFuncs = nil
|
|
}
|