atexit.go
This file
The walk stopped after 200 commits: lines older than 76efddd point at it.
bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 1–28why, one step back1package util23import (4 "sync"5)67var atExitFuncs []func()89// AtExit registers the function fn to be called on program termination.10// The functions will be called in reverse order they were registered.11func AtExit(fn func()) {12 if fn == nil {13 panic("AtExit called with nil func")14 }15 once := &sync.Once{}16 atExitFuncs = append(atExitFuncs, func() {17 once.Do(fn)18 })19}2021// RunAtExitFuncs runs any functions registered with AtExit().22func RunAtExitFuncs() {23 fns := atExitFuncs24 for i := len(fns) - 1; i >= 0; i-- {25 fns[i]()26 }27 atExitFuncs = nil28}