ctrlc

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: GPL-3.0 Imports: 5 Imported by: 1

README

go-ctrlc

Waits and gracefully stops golang program if CTRL+C called

Provides usefull CTRL+C interface, used to intercept ctrl+c signal to stop program outside or by internal command

Usage:

func main() {
	var ctrlc CtrlC
	defer ctrlc.DeferThisToWaitCtrlC(true)

	....

	go some_your_logic()
	....

	ctrl.InterceptKill(true, func() {
		fmt.Println("software was stopped via Ctrl+C")
	})
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CtrlC

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

func (*CtrlC) DeferThisToWaitCtrlC

func (c *CtrlC) DeferThisToWaitCtrlC()

func (*CtrlC) ForceStopProgram

func (c *CtrlC) ForceStopProgram()

stop program now

func (*CtrlC) InterceptKill

func (c *CtrlC) InterceptKill(stdout bool, stop func())

use defer DeferThisToWaitCtrlC if you called InterceptKill ! when called to stop via ctrl+c or ForceStop it call stop()

Jump to

Keyboard shortcuts

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