Clone this repo:

Branches

  1. 4927dd3 Remove dependency on github.com/maruel/ut by Marc-Antoine Ruel · 3 months ago master v1.0.1
  2. d27c852 I meant 1.8.x instead of 1.8.0 by Marc-Antoine Ruel · 3 months ago
  3. 926ddba Bump travis to go 1.8 and 1.x by Marc-Antoine Ruel · 3 months ago
  4. dd0db47 Update pre-commit-go to pcg. by Marc-Antoine Ruel · 2 years, 5 months ago v1.0.0
  5. 5aad64d Add ErrInterrupted. by Marc-Antoine Ruel · 2 years, 7 months ago

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