pool

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	Size         int               // 协程池容量
	Expiry       time.Duration     // 空闲协程存活时间
	PanicHandler func(interface{}) // Panic处理函数
}

Options 协程池配置选项

type Task

type Task func() // 定义任务类型

type WorkerPool

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

func NewWorkerPool

func NewWorkerPool(opts *Options) (*WorkerPool, error)

NewWorkerPool 创建协程池实例

func (*WorkerPool) Close

func (wp *WorkerPool) Close()

Close 关闭协程池

func (*WorkerPool) GetMu

func (wp *WorkerPool) GetMu() *sync.Mutex

GetMu 获取 *sync.Mutex

func (*WorkerPool) GetWaitGroup

func (wp *WorkerPool) GetWaitGroup() *sync.WaitGroup

GetWaitGroup 获取 *sync.WaitGroup

func (*WorkerPool) Resize

func (wp *WorkerPool) Resize(newSize int)

func (*WorkerPool) RunningWorkers

func (wp *WorkerPool) RunningWorkers() int

RunningWorkers 获取当前运行中的worker数量

func (*WorkerPool) Submit

func (wp *WorkerPool) Submit(task func()) error

Submit 提交任务到协程池(同步等待)

func (*WorkerPool) SubmitAsync

func (wp *WorkerPool) SubmitAsync(task func()) error

SubmitAsync 异步提交任务(不等待执行)

Source Files

  • ants_pool.go

Jump to

Keyboard shortcuts

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