workerpool

package
v0.0.0-...-d572d79 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: Apache-2.0, BSD-2-Clause Imports: 14 Imported by: 8 modules, 26 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithCancelPendingTasksOnShutdown

func WithCancelPendingTasksOnShutdown(cancelPendingTasksOnShutdown bool) options.Option[WorkerPool]

WithCancelPendingTasksOnShutdown is an option for the WorkerPool that allows to set if pending tasks should be canceled on shutdown.

func WithPanicOnSubmitAfterShutdown

func WithPanicOnSubmitAfterShutdown(panicOnSubmitAfterShutdown bool) options.Option[WorkerPool]

WithPanicOnSubmitAfterShutdown is an option for the WorkerPool that allows to set if a panic should be triggered when a task is submitted after the WorkerPool was shut down.

func WithWorkerCount

func WithWorkerCount(workerCount int) options.Option[WorkerPool]

WithWorkerCount is an option for the WorkerPool that allows to set the number of workers that are used to execute tasks.

Types

type Group

type Group struct {
	// PendingChildrenCounter contains the number of children that are currently pending.
	PendingChildrenCounter *syncutils.Counter
	// contains filtered or unexported fields
}

Group is a group of WorkerPools that can be managed as a whole.

func NewGroup

func NewGroup(name string) *Group

NewGroup creates a new Group.

func (*Group) CreateGroup

func (g *Group) CreateGroup(name string) *Group

CreateGroup creates a new Group with the given name and returns it.

func (*Group) CreatePool

func (g *Group) CreatePool(name string, opts ...options.Option[WorkerPool]) *WorkerPool

CreatePool creates a new WorkerPool with the given name and returns it.

func (*Group) Group

func (g *Group) Group(name string) (pool *Group, exists bool)

Group returns the Group with the given name.

func (*Group) IsShutdown

func (g *Group) IsShutdown() bool

IsShutdown returns true if the group was shutdown.

func (*Group) Name

func (g *Group) Name() (name string)

Name returns the name of the Group.

func (*Group) Pool

func (g *Group) Pool(name string) (pool *WorkerPool, exists bool)

Pool returns the WorkerPool with the given name.

func (*Group) Pools

func (g *Group) Pools() map[string]*WorkerPool

Pools returns all WorkerPools of the Group.

func (*Group) Root

func (g *Group) Root() *Group

Root returns the root Group of the Group.

func (*Group) Shutdown

func (g *Group) Shutdown()

Shutdown shuts down all child elements of the Group.

func (*Group) String

func (g *Group) String() string

String returns a human-readable string representation of the Group.

func (*Group) WaitChildren

func (g *Group) WaitChildren()

WaitChildren waits until all children of the Group are idle.

func (*Group) WaitParents

func (g *Group) WaitParents()

WaitParents waits until all parents of the Group are idle.

type Task

type Task struct {
	// contains filtered or unexported fields
}

Task is a task that is executed by a WorkerPool.

type WorkerPool

type WorkerPool struct {
	// Name is the name of the WorkerPool.
	Name string

	// PendingTasksCounter is the number of tasks that are currently pending.
	PendingTasksCounter *syncutils.Counter

	// Queue is the queue of tasks that are waiting to be executed.
	Queue *syncutils.Stack[*Task]

	// ShutdownComplete is a WaitGroup that is used to wait for the WorkerPool to shutdown.
	ShutdownComplete sync.WaitGroup
	// contains filtered or unexported fields
}

WorkerPool is a pool of workers that can execute tasks.

func New

func New(name string, opts ...options.Option[WorkerPool]) *WorkerPool

New creates a new WorkerPool with the given name and returns it.

func (*WorkerPool) DebounceFunc

func (w *WorkerPool) DebounceFunc() (debounce func(workerFunc func(), optStackTrace ...string))

DebounceFunc returns a function that can be used to submit a task that is canceled if the function is called with a new task before the previous task was executed.

func (*WorkerPool) IsRunning

func (w *WorkerPool) IsRunning() bool

IsRunning returns true if the WorkerPool is running.

func (*WorkerPool) Shutdown

func (w *WorkerPool) Shutdown() *WorkerPool

Shutdown shuts down the WorkerPool.

func (*WorkerPool) Start

func (w *WorkerPool) Start() *WorkerPool

Start starts the WorkerPool.

func (*WorkerPool) Submit

func (w *WorkerPool) Submit(workerFunc func(), optStackTrace ...string)

Submit submits a new task to the WorkerPool.

func (*WorkerPool) WorkerCount

func (w *WorkerPool) WorkerCount() int

WorkerCount returns the number of workers that are used to execute tasks.

Jump to

Keyboard shortcuts

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