MCPcopy Create free account
hub / github.com/git-bug/git-bug / RegisterCleaner

Function RegisterCleaner

util/interrupt/cleaner.go:31–65  ·  view source on GitHub ↗

RegisterCleaner is responsible for registering a cleaner function. When a function is registered, the Signal watcher is started in a goroutine.

(cleaner CleanerFunc)

Source from the content-addressed store, hash-verified

29// RegisterCleaner is responsible for registering a cleaner function.
30// When a function is registered, the Signal watcher is started in a goroutine.
31func RegisterCleaner(cleaner CleanerFunc) CancelFunc {
32 mu.Lock()
33 defer mu.Unlock()
34
35 w := &wrapper{f: cleaner}
36
37 cancel := func() {
38 mu.Lock()
39 defer mu.Unlock()
40 w.disabled = true
41 }
42
43 // prepend to later execute then in reverse order
44 cleaners = append([]*wrapper{w}, cleaners...)
45
46 if handlerCreated {
47 return cancel
48 }
49
50 handlerCreated = true
51 go func() {
52 ch := make(chan os.Signal, 1)
53 signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
54 <-ch
55 // Prevent un-terminated ^C character in terminal
56 fmt.Println()
57 errl := clean()
58 for _, err := range errl {
59 _, _ = fmt.Fprintln(os.Stderr, err)
60 }
61 os.Exit(1)
62 }()
63
64 return cancel
65}
66
67// clean invokes all registered cleanup functions, and returns a list of errors, if they exist.
68func clean() (errorList []error) {

Callers 12

TestGithubImporterFunction · 0.92
TestGithubPushPullFunction · 0.92
TestGitlabImportFunction · 0.92
TestGitlabPushPullFunction · 0.92
runBridgePullFunction · 0.92
runBridgePushFunction · 0.92
LoadBackendFunction · 0.92
PromptPasswordFunction · 0.92
TestRegisterAndCleanFunction · 0.85
TestCancelFunction · 0.85

Calls 3

cleanFunction · 0.85
LockMethod · 0.65
PrintlnMethod · 0.65

Tested by 8

TestGithubImporterFunction · 0.74
TestGithubPushPullFunction · 0.74
TestGitlabImportFunction · 0.74
TestGitlabPushPullFunction · 0.74
TestRegisterAndCleanFunction · 0.68
TestCancelFunction · 0.68