signal2

package
v0.3.37 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 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

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

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

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