Documentation
¶
Overview ¶
Package signal provides graceful signal handling for the StackEye CLI.
It intercepts SIGINT (Ctrl+C) and SIGTERM, cancels in-progress operations via context, runs registered cleanup functions, and exits with POSIX-standard codes (130 for SIGINT, 143 for SIGTERM).
Usage:
ctx, handler := signal.Setup()
handler.OnCleanup(func() { telemetry.Flush(2 * time.Second) })
exitCode := cmd.ExecuteWithContext(ctx)
os.Exit(handler.ExitCode(exitCode))
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler manages signal interception and cleanup coordination.
func Setup ¶
Setup registers SIGINT and SIGTERM handlers and returns a cancellable context along with a Handler for cleanup coordination. The returned context is canceled when a signal is received, allowing in-progress operations to terminate gracefully.
func (*Handler) Cancel ¶
func (h *Handler) Cancel()
Cancel cancels the handler's context. Called during normal shutdown to release the signal-watching goroutine.
func (*Handler) ExitCode ¶
ExitCode returns the appropriate exit code. If a signal was caught, it returns the POSIX signal exit code (130 for SIGINT, 143 for SIGTERM). Otherwise it returns the provided command exit code unchanged.
func (*Handler) OnCleanup ¶
func (h *Handler) OnCleanup(fn func())
OnCleanup registers a function to be called during graceful shutdown. Cleanup functions run in LIFO order (last registered runs first).
func (*Handler) RunCleanups ¶
func (h *Handler) RunCleanups()
RunCleanups executes all registered cleanup functions in LIFO order. Safe to call multiple times; subsequent calls are no-ops.