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)
| 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. |
| 77 | func (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 | } |
nothing calls this directly
no test coverage detected