package module
Version: v1.0.0 Latest Latest

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

Go to latest
Published: Jan 2, 2018 License: MIT Imports: 5 Imported by: 26



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.


package main

import "context"
import "github.com/caarlos0/ctrlc"

func main() {
    ctx, cancel := context.WithTimeout(context.Backgroud(), time.Second)
    defer cancel()
    ctrlc.Default.Run(ctx, func() error {
        // do something
        return nil



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



This section is empty.


View Source
var Default = New()

Default ctrlc instance


This section is empty.


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

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL