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 ¶
var Context context.Context
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 Register ¶
func Register(i int32)
Register thread so that Wait function will wait for it termination Register should be called before starting threads routine
Types ¶
This section is empty.