协程类

package
v0.0.0-...-fcd50c7 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

包grpool实现了可重用的goroutine池。 md5:8908f4659795e87e

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

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

Add 将一个新任务添加到默认的 Goroutine 池中。 该任务将会异步执行。 md5:2edd63bb852da48c

func AddWithRecover

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

AddWithRecover 将一个新的任务推送到默认池中,指定一个恢复函数。

可选的 `recoverFunc` 在执行 `userFunc` 时遇到任何 panic 时被调用。如果未传递或给定 `nil`,则忽略来自 `userFunc` 的 panic。任务将异步执行。 md5:4b448b4fd7caa604

func Jobs

func Jobs() int

Jobs 返回默认goroutine池当前的任务数量。 md5:d9b300d28d86f6c3

func Size

func Size() int

Size 返回默认goroutine池中的当前goroutine数量。 md5:f66351deb380810c

Types

type Func

type Func func(ctx context.Context)

Func 是包含上下文参数的池函数。 md5:6974cc4f941bf840

type Pool

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

Pool 使用池管理goroutine。 md5:b07df489dc176e1c

func New

func New(limit ...int) *Pool

New 创建并返回一个新的 goroutine 池对象。 参数 `limit` 用于限制最大 goroutine 数量, 默认情况下不限制。 md5:523f5833750663c7

func (*Pool) Add

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

Add 将一个新任务添加到池中。 该任务将会异步执行。 md5:69389d53e280086b

func (*Pool) AddWithRecover

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

AddWithRecover 将指定的恢复函数推送到队列中执行新任务。

可选的 `recoverFunc` 在执行 `userFunc` 时发生任何 panic 时被调用。如果未传递或给定 nil,它将忽略来自 `userFunc` 的 panic。任务将异步执行。 md5:764d1260466b9a5d

func (*Pool) Cap

func (p *Pool) Cap() int

Cap 返回池的容量。 这个容量在创建池时定义。 如果没有限制,则返回-1。 md5:1c6cae16429df1b2

func (*Pool) Close

func (p *Pool) Close()

Close 关闭goroutine池,导致所有goroutines退出。 md5:3d9c73ed9b0f4643

func (*Pool) IsClosed

func (p *Pool) IsClosed() bool

IsClosed 返回池是否已关闭。 md5:85755176347bcfea

func (*Pool) Jobs

func (p *Pool) Jobs() int

Jobs 返回池中的当前任务数。 注意,它返回的不是工作器/goroutine的数量,而是任务的数量。 md5:c82d92b33047974c

func (*Pool) Size

func (p *Pool) Size() int

Size 返回当前池中的goroutine数量。 md5:247eb1685633ccc3

type RecoverFunc

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

RecoverFunc 是一个带有上下文参数的池运行时panic恢复函数。 md5:745651d2d0aad841

Jump to

Keyboard shortcuts

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