graceful

package
v1.20210103.1 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2021 License: MIT Imports: 5 Imported by: 8

Documentation

Overview

Package graceful provides a mechanism to gracefully stop processes on os signals.

Index

Constants

This section is empty.

Variables

View Source
var DefaultShutdownSignals = []os.Signal{
	os.Interrupt, syscall.SIGTERM,
}

DefaultShutdownSignals are the default os signals to capture to shut down.

Functions

func Notify added in v1.20201204.1

func Notify(signals ...os.Signal) chan os.Signal

Notify returns a channel that listens for a given set of os signals.

func Shutdown

func Shutdown(hosted ...Graceful) error

Shutdown racefully stops a set hosted processes based on SIGINT or SIGTERM received from the os. It will return any errors returned by Start() that are not caused by shutting down the server. A "Graceful" processes *must* block on start.

func ShutdownBySignal

func ShutdownBySignal(hosted []Graceful, opts ...ShutdownOption) error

ShutdownBySignal gracefully stops a set hosted processes based on a set of variadic options. A "Graceful" processes *must* block on start. Fatal errors will be returned, that is, errors that are returned by either .Start() or .Stop(). Panics are not caught by graceful, and it is assumed that your .Start() or .Stop methods will catch relevant panics.

Types

type Graceful

type Graceful interface {
	Start() error // this call must block
	Stop() error
}

Graceful is a server that can start and stop.

type ShutdownOption added in v1.20201204.1

type ShutdownOption func(*ShutdownOptions)

ShutdownOption is a mutator for shutdown options.

func OptDefaultShutdownSignal added in v1.20201204.1

func OptDefaultShutdownSignal() ShutdownOption

OptDefaultShutdownSignal returns an option that sets the shutdown signal to the defaults.

func OptShutdownSignal added in v1.20201204.1

func OptShutdownSignal(signal chan os.Signal) ShutdownOption

OptShutdownSignal sets the shutdown signal.

type ShutdownOptions added in v1.20201204.1

type ShutdownOptions struct {
	ShutdownSignal chan os.Signal
}

ShutdownOptions are the options for graceful shutdown.

Jump to

Keyboard shortcuts

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