grpool

原文:https://pkg.go.dev/github.com/gogf/gf/v2@v2.6.4/os/grpool

Package grpool implements a goroutine reusable pool.

​ 软件包 grpool 实现了一个 goroutine 可重用池。

常量

This section is empty.

变量

This section is empty.

函数

func Add

1
func Add(ctx context.Context, f Func) error

Add pushes a new job to the default goroutine pool. The job will be executed asynchronously.

​ Add 将新作业推送到默认的 goroutine 池。作业将异步执行。

func AddWithRecover

1
func AddWithRecover(ctx context.Context, userFunc Func, recoverFunc RecoverFunc) error

AddWithRecover pushes a new job to the default pool with specified recover function.

​ AddWithRecover 使用指定的恢复函数将新作业推送到默认池。

The optional recoverFunc is called when any panic during executing of userFunc. If recoverFunc is not passed or given nil, it ignores the panic from userFunc. The job will be executed asynchronously.

​ 当 执行 期间出现任何 panic 时,将调用可选 userFuncrecoverFunc 。如果 recoverFunc 未传递或给出 nil,则忽略来自 userFunc 的恐慌。作业将异步执行。

func Jobs

1
func Jobs() int

Jobs returns current job count of default goroutine pool.

​ Jobs 返回默认 goroutine 池的当前作业计数。

func Size

1
func Size() int

Size returns current goroutine count of default goroutine pool.

​ Size 返回默认 goroutine 池的当前 goroutine 计数。

类型

type Func

1
type Func func(ctx context.Context)

Func is the pool function which contains context parameter.

​ Func 是包含 context 参数的池函数。

type Pool

1
2
3
type Pool struct {
	// contains filtered or unexported fields
}

Pool manages the goroutines using pool.

​ Pool 使用 pool 管理 goroutine。

func New

1
func New(limit ...int) *Pool

New creates and returns a new goroutine pool object. The parameter limit is used to limit the max goroutine count, which is not limited in default.

​ New 创建并返回一个新的 goroutine 池对象。该参数 limit 用于限制最大 goroutine 计数,默认情况下不受限制。

(*Pool) Add

1
func (p *Pool) Add(ctx context.Context, f Func) error

Add pushes a new job to the pool. The job will be executed asynchronously.

​ 添加将新作业推送到池中。作业将异步执行。

(*Pool) AddWithRecover

1
func (p *Pool) AddWithRecover(ctx context.Context, userFunc Func, recoverFunc RecoverFunc) error

AddWithRecover pushes a new job to the pool with specified recover function.

​ AddWithRecover 使用指定的 recover 函数将新作业推送到池中。

The optional recoverFunc is called when any panic during executing of userFunc. If recoverFunc is not passed or given nil, it ignores the panic from userFunc. The job will be executed asynchronously.

​ 当 执行 期间出现任何 panic 时,将调用可选 userFuncrecoverFunc 。如果 recoverFunc 未传递或给出 nil,则忽略来自 userFunc 的恐慌。作业将异步执行。

(*Pool) Cap

1
func (p *Pool) Cap() int

Cap returns the capacity of the pool. This capacity is defined when pool is created. It returns -1 if there’s no limit.

​ Cap 返回池的容量。此容量是在创建池时定义的。如果没有限制,则返回 -1。

(*Pool) Close

1
func (p *Pool) Close()

Close closes the goroutine pool, which makes all goroutines exit.

​ Close 关闭 goroutine 池,这将使所有 goroutine 退出。

(*Pool) IsClosed

1
func (p *Pool) IsClosed() bool

IsClosed returns if pool is closed.

​ 如果池已关闭,则返回 IsClosed。

(*Pool) Jobs

1
func (p *Pool) Jobs() int

Jobs returns current job count of the pool. Note that, it does not return worker/goroutine count but the job/task count.

​ 作业返回池的当前作业计数。请注意,它不会返回 worker/goroutine 计数,而是返回作业/任务计数。

(*Pool) Size

1
func (p *Pool) Size() int

Size returns current goroutine count of the pool.

​ size 返回池的当前 goroutine 计数。

type RecoverFunc <-2.1.0

1
type RecoverFunc func(ctx context.Context, exception error)

RecoverFunc is the pool runtime panic recover function which contains context parameter.

​ RecoverFunc 是包含上下文参数的池运行时紧急恢复函数。

最后修改 October 10, 2024: 更新 (a4b8f85)