interrupted

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2022 License: MIT Imports: 5 Imported by: 0

README

interrupted

A simple wrapper to handle interrupts in Go with a Context and Waitgroup

Usage

package main

func main() {
	WaitForInterrupt(func(ctx context.Context, wg *sync.WaitGroup) {
		go asyncFunction1(ctx, wg)
        asyncFunction2(ctx, wg) // It is important to call this without a goroutine to allow the waitgroup to get the correct count, else the program will exit before the asyncFunction1 has started
	})
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Wait

func Wait(function func(context.Context, *sync.WaitGroup))

Wait waits for an interrupt signal to be received, then cancels the context and waits for the wait group to finish. If a second interrupt signal is received, the program is terminated.

Types

This section is empty.

Jump to

Keyboard shortcuts

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