pool

package
v0.0.0-...-021ab65 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 默认协程清理时间
	DefaultCleanIntervalTime = 2 * time.Second

	//工作状态
	Waiting int = 0
	Working int = 1
	Idling  int = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

type Pool struct {
	Ctx context.Context // 控制是否终止协程
	// contains filtered or unexported fields
}

厂房

func NewPool

func NewPool(size int32, prune bool, expiry_time time.Duration) (*Pool, context.CancelFunc)

新建一个厂房

func (*Pool) Cap

func (p *Pool) Cap() int32

厂房能容纳同时工作的工人数量

func (*Pool) Close

func (p *Pool) Close()

关闭协程池,让所有worker退出运行以防goroutine泄露,必须先调用Wait

func (*Pool) ReSize

func (p *Pool) ReSize(size int32)

调整厂房工人的数量

func (*Pool) Running

func (p *Pool) Running() int32

正在工作的工人数

func (*Pool) Submit

func (p *Pool) Submit(task *Task) error

提交一个任务

func (*Pool) Wait

func (p *Pool) Wait()

等待正在工作中的工人完成任务

type Task

type Task struct {
	TaskFunc func([]interface{})
	Param    []interface{}
}

需要执行的任务

Jump to

Keyboard shortcuts

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