Help us shape the future of Go! Take the 2026 Go Developer Survey

ctrlc

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2022 License: MIT Imports: 5 Imported by: 40

README

ctrlc

CTRL-C is a Go library that provides an easy way of having a task that is context-aware and deals with SIGINT and SIGTERM signals.

Usage

Check the _examples folder.

You can run it like this:

$ go run _examples/main.go
# will fail because the last task returns an error

$ go run _examples/main.go -timeout 1s
# will fail due to context timeout

$ go run _examples/main.go
# press ctrl-c
# will cancel the context due to interrupt and error

Documentation

Overview

Package ctrlc provides an easy way of having a task that is context-aware and that also deals with interrupt and term signals.

Index

Constants

This section is empty.

Variables

View Source
var Default = New()

Default ctrlc instance

Functions

This section is empty.

Types

type Ctrlc

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

Ctrlc is the task ctrlc

func New

func New() *Ctrlc

New returns a new ctrlc with its internals setup.

func (*Ctrlc) Run

func (c *Ctrlc) Run(ctx context.Context, task Task) error

Run executes a given task with a given context, dealing with its timeouts, cancels and SIGTERM and SIGINT signals. It will return an error if the context is canceled, if deadline exceeds, if a SIGTERM or SIGINT is received and of course if the task itself fails.

type Task

type Task func() error

Task is function that can be executed by a ctrlc

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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