interrupt

package
v1.53.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Signals are all interrupt signals.

As opposed to os.Interrupt, this adds syscall.SIGTERM for unix-like platforms. For other platforms, this is just os.Interrupt

Functions

func Handle added in v1.46.0

func Handle(ctx context.Context) context.Context

Handle returns a copy of the parent context.Context that is marked done when an interrupt signal arrives or when the parent Context's Done channel is closed, whichever happens first.

Signal handling is unregistered automatically by this function when the first interrupt signal arrives, which will restore the default interrupt signal behavior of Go programs (to exit).

In effect, this function is functionally equivalent to:

ctx, cancel := signal.NotifyContext(ctx, interrupt.Signals...)
go func() {
  <-ctx.Done()
  cancel()
}()

Most programs should wrap their contexts using this function to enable interrupt signal handling. The first interrupt signal will result in the context's Done channel closing. The second interrupt signal will result in the program exiting.

func main() {
  ctx := interrupt.Handle(context.Background())
  ...
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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