sigint

package
v0.0.0-...-7bc1492 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2018 License: Apache-2.0 Imports: 3 Imported by: 9

Documentation

Overview

Package sigint provides a Handler that calls exit handlers when the process has been interrupted by sigint (a ctrl-c typically).

Index

Constants

View Source
const (
	// SigInt is the exit code that the shell returns if terminated with CTRL-C
	SigInt = 130
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Handler waits on a sigint and exits the program after calling the set of callbacks.

var (
	// DefaultHandler is the singleton for this package, because of the nature
	// of os.Exit() there's really no point to have multiple Handler's lying
	// around as only one can ever be executed.
	DefaultHandler *Handler
)

func NewHandler

func NewHandler() *Handler

NewHandler creates a new sigint handler. This starts a goroutine automatically to handle the signal.

func (*Handler) Add

func (h *Handler) Add(callbacks ...func())

Add callbacks to the list of sigint handlers to call when the signal is received.

func (*Handler) Exit

func (h *Handler) Exit(code int)

Exit the process with an exit code.

func (*Handler) Run

func (h *Handler) Run()

Run the handler, waiting for the signal.

Jump to

Keyboard shortcuts

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