interrupt

package module
Version: v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2020 License: Apache-2.0 Imports: 4 Imported by: 13

README

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

Documentation

Overview

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.
}

Index

Constants

This section is empty.

Variables

View Source
var Channel <-chan bool

Channel continuously sends true once the interrupt signal was set. It can be used in select section to handle interrupted process.

View Source
var ErrInterrupted = errors.New("interrupted")

ErrInterrupted can be used as an error to signal that a process was interrupted but didn't fail in any other way. This permits disambiguating from any other genuine error.

Functions

func HandleCtrlC

func HandleCtrlC()

HandleCtrlC initializes an handler to handle SIGINT, which is normally sent on Ctrl-C.

This function is provided for convenience. To handle other situations, use Set() directly.

func IsSet

func IsSet() bool

IsSet returns true once the interrupt signal was set. It is meant to be used when polling for status instead of using channel selection.

func Set

func Set()

Set sets the interrupt signal. It is to be used when the process must exit as soon as possible.

Types

This section is empty.

Source Files

Jump to

Keyboard shortcuts

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