sigcancel

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2021 License: MIT Imports: 5 Imported by: 0

README

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CancelOnSignal

func CancelOnSignal(cancel context.CancelFunc)

CancelOnSignal is a compact, idiomatic way to listen for OS signals in the main of a Go program. The intent here is to reduce the tedium of setting up proper signal handling and just compact the whole thing into what Go writers are used to dealing with: context cancellations. Usage looks like this:

func main() {
    ctx, cancel := context.WithCancel(context.Background())
    go sigcancel.CancelOnSignal(cancel)
    go startWorking(ctx)
    <-ctx.Done()
    fmt.Println("shutting down...")
    // clean up services / workload
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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