interrupt

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Global = New(func(o os.Signal) {
	os.Exit(1)
})

Global is the global interrupt handler

Functions

This section is empty.

Types

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler guarantees execution of notifications after a critical section (the function passed to a Run method), even in the presence of process termination. It guarantees exactly once invocation of the provided notify functions.

func New

func New(final func(os.Signal)) *Handler

New creates a new handler that guarantees all notify functions are run after the critical section exits (or is interrupted by the OS), then invokes the final handler. If no final handler is specified, the default final is `os.Exit(1)`. A handler can only be used for one critical section.

func (*Handler) Run

func (h *Handler) Run(fn func() error, notify func()) error

Run ensures that the function fn is run and runs the notify function if interrupted meanwhile

func (*Handler) RunAlways

func (h *Handler) RunAlways(fn func() error, notify func()) error

RunAlways ensures that the function fn is run and runs the notify function if interrupted meanwhile or the function has ended

func (*Handler) Signal

func (h *Handler) Signal(s os.Signal)

Signal is called when an os.Signal is received, and guarantees that all notifications are executed, then the final handler is executed. This function should only be called once per Handler instance.

func (*Handler) Start

func (h *Handler) Start()

Start ensures the handler is started and ready for incoming signals

func (*Handler) Stop

func (h *Handler) Stop()

Stop ensures we do not watch for incoming signals anymore

Jump to

Keyboard shortcuts

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