exithandler

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

The exithandler package exposes two useful functions to handle program terminations:

The first one is `Handle` which will blocked on SIGINT and SIGTERM signals until one of those are sent and then executes the provided function.

func main() {
	// some things to be defined

	go exithandler.Handle(ctx, func(context.Context) {
		// some things to close or execute when the program terminates
	})
}

The second one is `HandleFunc` which does the exact same thing, the only difference is that it returns the function which will wait and does not wait directly (as provided in below example).

func main() {
	// some things to be defined

	exithandler := exithandler.HandleFunc(ctx, func(context.Context) {
		// some things to close or execute when the program terminates
	})

	// other things to do

	exithandler()
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handle

func Handle(parent context.Context, exithandler HandlerFunc)

Handle inits a new context listening to the global signals and waits on Done channel to execute the given input function.

func HandleFunc

func HandleFunc(parent context.Context, exithandler HandlerFunc) func()

HandleFunc returns a function initializing a new context listening to the global signals and awaiting on Done channel to execute the given input function.

Types

type HandlerFunc

type HandlerFunc func(context.Context)

HandlerFunc represents an exit function to be executed when the program receives a SIGINT ou SIGTERM signal.

Jump to

Keyboard shortcuts

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