signal

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	context.Context
	Cancel func()
	// contains filtered or unexported fields
}

Context wraps a context and captures the signal that cancelled it.

func NewContext

func NewContext(parent context.Context) *Context

NewContext creates a context that is cancelled on SIGTERM (standard termination). It captures SIGINT (Interrupt) separately to allow the state machine to handle it.

Usage:

ctx := signal.NewContext(context.Background())
defer ctx.Cancel()

select {
case <-ctx.Done():
    // Check if it was a signal or just a cancel
    if sig := ctx.Signal(); sig != nil {
        fmt.Println("Received signal:", sig)
    }
}

func (*Context) Signal

func (sc *Context) Signal() os.Signal

Signal returns the signal that caused the context to be cancelled/interrupted, or nil.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL