ctrlc

package
v0.5.16 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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