Documentation
¶
Overview ¶
Package signalhandler is used to make it easier to safely and consistently use a signal handler.
Example ¶
// Create a channel, that when closed signals
// other stuff they need to stop
var stopChan = make(chan struct{})
// Create a closure, literally.
f := func(os.Signal) { close(stopChan) }
// Install our closure as a handler for when we feel a Ctrl-C, etc.
done := Simple(f)
defer done() // eventually let the signal handler know it should exit.
// continue on our lives, checking for <-stopChan where necessary
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DoneFunc ¶
type DoneFunc func()
DoneFunc is a definition for a closure returned to signal we should stop our listening.
func Handler ¶
func Handler(f HandlerFunc, stopOnSignal bool, sigs ...os.Signal) DoneFunc
Handler installs the HandlerFunc, optionally stopping when a signal is received, for a list of specified signals.
func Simple ¶
func Simple(f HandlerFunc) DoneFunc
Simple installs the HandlerFunc, listening only once for SIGINT or SIGKILL and then stops.
type HandlerFunc ¶
HandlerFunc is a definition of a closure one can provides to the Handler for when a representative Signal is seen.
Click to show internal directories.
Click to hide internal directories.