threadgroup

package
v1.0.1-beta.2 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 New

func New() *ThreadGroup

New creates a new threadgroup

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.

Jump to

Keyboard shortcuts

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