signalhandler

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2025 License: Unlicense Imports: 3 Imported by: 2

README

signalhandler

import "github.com/cognusion/go-signalhandler"

Overview

Package signalhandler is used to make it easier to safely and consistently use a signal handler.

Example :
// Create a channel, that when closed signals
// other stuff they need to stop
var stopChan = make(chan struct{})

// Create a closure, literally.
f := func(os.Signal) { close(stopChan) }

// Install our closure as a handler for when we feel a Ctrl-C, etc.
done := Simple(f)
defer done() // eventually let the signal handler know it should exit.

// continue on our lives, checking for <-stopChan where necessary

Index

Examples
Package files

sigs.go

type DoneFunc

type DoneFunc func()

DoneFunc is a definition for a closure returned to signal we should stop our listening.

func Handler
func Handler(f HandlerFunc, stopOnSignal bool, sigs ...os.Signal) DoneFunc

Handler installs the HandlerFunc, optionally stopping when a signal is received, for a list of specified signals.

func Simple
func Simple(f HandlerFunc) DoneFunc

Simple installs the HandlerFunc, listening only once for SIGINT or SIGKILL and then stops.

type HandlerFunc

type HandlerFunc func(os.Signal)

HandlerFunc is a definition of a closure one can provides to the Handler for when a representative Signal is seen.


Generated by godoc2md

Documentation

Overview

Package signalhandler is used to make it easier to safely and consistently use a signal handler.

Example
// Create a channel, that when closed signals
// other stuff they need to stop
var stopChan = make(chan struct{})

// Create a closure, literally.
f := func(os.Signal) { close(stopChan) }

// Install our closure as a handler for when we feel a Ctrl-C, etc.
done := Simple(f)
defer done() // eventually let the signal handler know it should exit.

// continue on our lives, checking for <-stopChan where necessary

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DoneFunc

type DoneFunc func()

DoneFunc is a definition for a closure returned to signal we should stop our listening.

func Handler

func Handler(f HandlerFunc, stopOnSignal bool, sigs ...os.Signal) DoneFunc

Handler installs the HandlerFunc, optionally stopping when a signal is received, for a list of specified signals.

func Simple

func Simple(f HandlerFunc) DoneFunc

Simple installs the HandlerFunc, listening only once for SIGINT or SIGKILL and then stops.

type HandlerFunc

type HandlerFunc func(os.Signal)

HandlerFunc is a definition of a closure one can provides to the Handler for when a representative Signal is seen.

Jump to

Keyboard shortcuts

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