shutdown

package
v1.1.0-beta Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package shutdown provides a mechanism for graceful shutdown of multithreaded programs. It combines functionality of WaitGroups and context.WithCancel, to account number running threads and notify threads waiting in the blocking calls.

Setup/Wait allowed to be called sequentially only Register can be called only from the thread where Setup/Wait called or from the thread for which register has been called already.

Index

Constants

This section is empty.

Variables

Context will be canceled when Initiate is called

Functions

func Done

func Done()

Done should be called on threads routine exit to notify Wait that thread has * finished

func Initiate

func Initiate()

Initiate notifies threads of program's intent to terminate Should be called by one thread only

func InitiateAndWait

func InitiateAndWait()

InitiateAndWait is a helper which is often used in tests, where we want to Initiate shutdown and Wait program to shutdown on function exit

func Initiated

func Initiated() bool

Initiated is used by threads to check if program is being terminated

func InitiatedCh

func InitiatedCh() <-chan struct{}

InitiatedCh is used by threads to receive terminate notification from channel

func NumProcs

func NumProcs() int32

NumProcs returns number of currently running threads

func Register

func Register(i int32)

Register thread so that Wait function will wait for it termination Register should be called before starting threads routine

func Setup

func Setup()

Setup initializes shutdown framework. Setup signal listener for SIGINT, * SIGTERM

func Wait

func Wait()

Wait waits for all the registered threads to terminate

Types

This section is empty.

Jump to

Keyboard shortcuts

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