signals

package
v0.2.52 Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const ErrSignalTrapped = "signal trapped"

ErrSignalTrapped is returned by the SignalTrap.Wait when the expected signals caught.

Variables

This section is empty.

Functions

func SetupSignalHandler

func SetupSignalHandler() (stopCh <-chan struct{})

SetupSignalHandler registered for SIGTERM and SIGINT. A stop channel is returned which is closed on one of these signals. If a second signal is caught, the program is terminated with exit code 1.

Types

type SignalTrap added in v0.2.45

type SignalTrap chan os.Signal

SignalTrap wraps os.Signal channel to provide high level API above it.

trap := make(chan os.Signal)
signal.Notify(trap, os.Interrupt)
SignalTrap(trap).Wait(context.Background())

func Termination added in v0.2.45

func Termination() SignalTrap

Termination returns trap for termination signals.

server := new(http.Server)
go log.Println(server.ListenAndServe())

err := sync.Termination().Wait(context.Background())
if err == sync.ErrSignalTrapped {
	log.Println("shutting down the server", server.Shutdown(context.Background()))
}

func (SignalTrap) Wait added in v0.2.45

func (trap SignalTrap) Wait(ctx context.Context) error

Wait blocks until one of the expected signals caught or the Context closed. It unregisters from the notification and closes itself.

Jump to

Keyboard shortcuts

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