Documentation ¶
Index ¶
- func WithCancelPendingTasksOnShutdown(cancelPendingTasksOnShutdown bool) options.Option[WorkerPool]
- func WithPanicOnSubmitAfterShutdown(panicOnSubmitAfterShutdown bool) options.Option[WorkerPool]
- func WithWorkerCount(workerCount int) options.Option[WorkerPool]
- type Group
- func (g *Group) CreateGroup(name string) *Group
- func (g *Group) CreatePool(name string, opts ...options.Option[WorkerPool]) *WorkerPool
- func (g *Group) Group(name string) (pool *Group, exists bool)
- func (g *Group) IsShutdown() bool
- func (g *Group) Name() (name string)
- func (g *Group) Pool(name string) (pool *WorkerPool, exists bool)
- func (g *Group) Pools() map[string]*WorkerPool
- func (g *Group) Root() *Group
- func (g *Group) Shutdown()
- func (g *Group) String() string
- func (g *Group) WaitChildren()
- func (g *Group) WaitParents()
- type Task
- type WorkerPool
- func (w *WorkerPool) DebounceFunc() (debounce func(workerFunc func(), optStackTrace ...string))
- func (w *WorkerPool) IsRunning() bool
- func (w *WorkerPool) Shutdown() *WorkerPool
- func (w *WorkerPool) Start() *WorkerPool
- func (w *WorkerPool) Submit(workerFunc func(), optStackTrace ...string)
- func (w *WorkerPool) WorkerCount() int
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 (*Group) CreateGroup ¶
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) IsShutdown ¶
IsShutdown returns true if the group was shutdown.
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) Shutdown ¶
func (g *Group) Shutdown()
Shutdown shuts down all child elements 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) 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.