ctrlc

package
v0.3.55 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AbortedByUser = abortedErr{}

Functions

func ClearHandlers

func ClearHandlers()

ClearHandlers removes all Ctrl+C signal handlers. Use with care.

func HookCancelableContext

func HookCancelableContext(ctx context.Context, cancelFn context.CancelFunc) (context.Context, context.CancelFunc)

HookCancelableContext returns a context that is canceled when the user presses Ctrl+C. The context is canceled with AbortedByUser.

func HookContext

func HookContext(ctx context.Context) (context.Context, context.CancelFunc)

HookContext returns a context that is canceled when the user presses Ctrl+C. The context is canceled with AbortedByUser. If you're wrapping a context that already has a cancel function, use HookCancelableContext instead.

func Signals

func Signals() []os.Signal

Signals returns any signals that could correspond to Ctrl+C.

Types

type Handle

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

func Hook

func Hook(event func()) Handle

Hook registers a function to be called when the user presses Ctrl+C. It returns a Handle, which must have its Done() method called to clean up. The event function will never be called more than once.

func (Handle) Done

func (h Handle) Done()

Done cleans up signal handlers.

Jump to

Keyboard shortcuts

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