MCPcopy
hub / github.com/marmotedu/iam / Run

Method Run

internal/iamctl/util/interrupt/interrupt.go:77–93  ·  view source on GitHub ↗

Run ensures that any notifications are invoked after the provided fn exits (even if the process is interrupted by an OS termination signal). Notifications are only invoked once per Handler instance, so calling Run more than once will not behave as the user expects.

(fn func() error)

Source from the content-addressed store, hash-verified

75// process is interrupted by an OS termination signal). Notifications are only invoked once
76// per Handler instance, so calling Run more than once will not behave as the user expects.
77func (h *Handler) Run(fn func() error) error {
78 ch := make(chan os.Signal, 1)
79 signal.Notify(ch, terminationSignals...)
80 defer func() {
81 signal.Stop(ch)
82 close(ch)
83 }()
84 go func() {
85 sig, ok := <-ch
86 if !ok {
87 return
88 }
89 h.Signal(sig)
90 }()
91 defer h.Close()
92 return fn()
93}

Callers

nothing calls this directly

Implementers 1

RedisClusterpkg/storage/redis_cluster.go

Calls 4

SignalMethod · 0.95
CloseMethod · 0.95
NotifyMethod · 0.80
StopMethod · 0.80

Tested by

no test coverage detected