interrupt

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2017 License: Apache-2.0 Imports: 4 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

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

A Handler executes notification functions after a critical section (the function passed to its Run method), even in the presence of process termination via a termination signal. A final handler is executed if a termination signal is caught. The handler guarantees that the provided notify functions will be called at most once. A Handler is not reusable in the sense that its Run method should be called only once: calling it more times will not execute any of notify nor final functions.

func New

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

New creates a new Handler. The final function will be called only if a termination signal is caught, after all notify functions are run. If final is nil, it defaults to os.Exit(2). The final function may call os.Exit if exiting is desired. The notify functions will be called when a termination signal is caught, or after the argument to the Run method completes.

func (*Handler) Run

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

Run calls fn in the current goroutine, while waiting for a termination signal in a separate goroutine. If a signal is caught while this method is running, the notify functions will be called sequentially in order, and then the final function is called. Otherwise, only the notify functions are called after fn returns. The fn function may not complete, for example in case of a call to os.Exit.

Jump to

Keyboard shortcuts

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