work

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCapacity = errors.New("Thread Pool At Capacity")
)
View Source
var ErrorInvalidMinRoutines = errors.New("Invalid minimum number of routines")
View Source
var ErrorInvalidStatTime = errors.New("Invalid duration for stat time")

Functions

This section is empty.

Types

type Pool

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

Pool 提供一个能执行工作任务的的协程池

func NewWork

func NewWork(minRoutines int, statTime time.Duration, logFunc func(message string)) (*Pool, error)

func (*Pool) Add

func (p *Pool) Add(routines int)

func (*Pool) Run

func (p *Pool) Run(work Worker)

func (*Pool) Shutdown

func (p *Pool) Shutdown()

type PoolWorker

type PoolWorker interface {
	DoWork(workRoutine int)
}

PoolWorker 必须实现此接口才能作为工作任务被执行

type WorkPool

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

WorkPool 实现了一个工作池,可以指定并发等级和队列容量

func NewWorkPool

func NewWorkPool(numberOfRoutines int, queueCapacity int32) *WorkPool

func (*WorkPool) ActiveRoutines

func (p *WorkPool) ActiveRoutines() int32

ActiveRoutines 正在执行工作的 goroutine 数量

func (*WorkPool) PostWork

func (p *WorkPool) PostWork(goRoutine string, work PoolWorker) (err error)

提交工作到工作池

func (*WorkPool) QueuedWork

func (p *WorkPool) QueuedWork() int32

QueuedWork 正在执行的任务数量

func (*WorkPool) Shutdown

func (p *WorkPool) Shutdown(goRoutine string) (err error)

Shutdown 释放资源并停止所有正在处理的工作

type Worker

type Worker interface {
	Work(id int)
}

必须实现 Worker 接口的任务才能被工作池管理和执行

Jump to

Keyboard shortcuts

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