workerpool

package
v0.0.0-...-503c688 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option[T any] interface {
	Apply(pool *WorkerPool[T])
}

Option is the config option for WorkerPool.

type OptionSkipRegister

type OptionSkipRegister[T any] struct{}

OptionSkipRegister is an option to skip register the worker pool to resource manager.

func (OptionSkipRegister[T]) Apply

func (OptionSkipRegister[T]) Apply(pool *WorkerPool[T])

Apply implements the Option interface.

type Worker

type Worker[T any] interface {
	HandleTask(task T)
	Close()
}

Worker is worker interface.

type WorkerPool

type WorkerPool[T any] struct {
	// contains filtered or unexported fields
}

WorkerPool is a pool of workers.

func NewWorkerPool

func NewWorkerPool[T any](name string, component util.Component, numWorkers int,
	createWorker func() Worker[T], opts ...Option[T]) (*WorkerPool[T], error)

NewWorkerPool creates a new worker pool.

func (*WorkerPool[T]) AddTask

func (p *WorkerPool[T]) AddTask(task T)

AddTask adds a task to the pool.

func (*WorkerPool[T]) Cap

func (p *WorkerPool[T]) Cap() int32

Cap returns the capacity of the pool.

func (*WorkerPool[T]) GetOriginConcurrency

func (p *WorkerPool[T]) GetOriginConcurrency() int32

GetOriginConcurrency return the concurrency of the pool at the init.

func (*WorkerPool[T]) LastTunerTs

func (p *WorkerPool[T]) LastTunerTs() time.Time

LastTunerTs returns the last time when the pool was tuned.

func (*WorkerPool[T]) Name

func (p *WorkerPool[T]) Name() string

Name returns the name of the pool.

func (*WorkerPool[T]) ReleaseAndWait

func (p *WorkerPool[T]) ReleaseAndWait()

ReleaseAndWait releases the pool and wait for complete.

func (*WorkerPool[T]) Running

func (p *WorkerPool[T]) Running() int32

Running returns the number of running workers.

func (*WorkerPool[T]) Tune

func (p *WorkerPool[T]) Tune(numWorkers int32)

Tune tunes the pool to the specified number of workers.

Jump to

Keyboard shortcuts

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