Package interrupt is a single global way to handle process interruption in Go
Go
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.travis.yml
LICENSE
README.md
interrupt.go
interrupt_test.go

README.md

interrupt

Package interrupt is a single global way to handle process interruption.

It is useful for both long lived process to implement controlled shutdown and for CLI tool to handle early termination.

The interrupt signal can be set exactly once in the process lifetime and cannot be unset. The signal can optionally be set automatically on Ctrl-C/os.Interrupt. When set, it is expected the process to abort any on-going execution early.

The signal can be read via two ways:

select {
case <- interrupt.Channel:
  // Handle abort.
case ...
  ...
default:
}

or

if interrupt.IsSet() {
  // Handle abort.
}

GoDoc Build Status Coverage Status