Documentation
¶
Overview ¶
Package stop implements the stopper pattern for golang concurrency management. The main use case is to gracefully
exit an application. The pattern allows for a hierarchy of stoppers. Each package should have its own unexported stopper. The package should maintain startup and shutdown exported methods. If the stopper should stop when another stopper for a different package stops, the parent argument for the initialization of a stopper be used to create the dependency.
The package also comes with a debugging tool to help in determining why and where a stopper is not stopping as expected. If a more complex concurrency is used, it is recommended to implement the library using `DoneNamed` and `AddNamed`. In addition to the standard `Done` functionality, it allows a functional named representation of the type of go routine being completed. This works in conjunction with `AddNamed`. If the init of the stopper Group happens with `NewDebug` instead of `New` special tracking and logging is enabled where it will print out the remaining routines' functional name and how many it is waiting on to complete the stop after each call to `DoneNamed`. This allows easy debugging by just changing the init of the stopper instead of all the references as long as the library is implemented with `DoneNamed` and `AddNamed`. For simple uses of the stopper pattern this is not needed and the standard `Add` and `Done` should be used.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Group ¶
Stopper extends sync.WaitGroup to add a convenient way to stop running goroutines
func New ¶
New allocates and returns a new instance. Use New(parent) to create an instance that is stopped when parent is stopped.
func NewDebug ¶
NewDebug allows you to debug the go routines the group waits on. In order to leverage this, AddNamed and DoneNamed should be used.
func (*Group) AddNamed ¶
AddNamed is the same as Add but will register the functional name of the routine for later output. See `DoneNamed`.
func (*Group) DoneNamed ¶
DoneNamed is the same as `Done` but will output the functional name of all remaining named routines and the waiting on count.
func (*Group) Stop ¶
func (s *Group) Stop()
Stop signals any listening processes to stop. After the first call, Stop() does nothing.
func (*Group) StopAndWait ¶
func (s *Group) StopAndWait()
StopAndWait is a convenience method to close the channel and wait for goroutines to return.