Documentation ¶
Index ¶
- Variables
- type ThreadGroup
- func (tg *ThreadGroup) Add() (func(), error)
- func (tg *ThreadGroup) AddContext(parent context.Context) (context.Context, context.CancelFunc, error)
- func (tg *ThreadGroup) Done() <-chan struct{}
- func (tg *ThreadGroup) Stop()
- func (tg *ThreadGroup) WithContext(parent context.Context) (context.Context, context.CancelFunc)
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("threadgroup closed")
ErrClosed is returned when the threadgroup has already been stopped
Functions ¶
This section is empty.
Types ¶
type ThreadGroup ¶
type ThreadGroup struct {
// contains filtered or unexported fields
}
A ThreadGroup provides synchronization between a module and its goroutines to enable clean shutdowns
func (*ThreadGroup) Add ¶
func (tg *ThreadGroup) Add() (func(), error)
Add adds a new thread to the group, done must be called to signal that the thread is done. Returns ErrClosed if the threadgroup is already closed.
func (*ThreadGroup) AddContext ¶
func (tg *ThreadGroup) AddContext(parent context.Context) (context.Context, context.CancelFunc, error)
AddContext adds a new thread to the group and returns a copy of the parent context. It is a convenience function combining Add and WithContext.
func (*ThreadGroup) Done ¶
func (tg *ThreadGroup) Done() <-chan struct{}
Done returns a channel that will be closed when the threadgroup is stopped
func (*ThreadGroup) Stop ¶
func (tg *ThreadGroup) Stop()
Stop stops accepting new threads and waits for all existing threads to close
func (*ThreadGroup) WithContext ¶
func (tg *ThreadGroup) WithContext(parent context.Context) (context.Context, context.CancelFunc)
WithContext returns a copy of the parent context. The returned context will be cancelled if the parent context is cancelled or if the threadgroup is stopped.