gpool

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GPool

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

GPool 定义了一个协程池的结构体

func NewGPool

func NewGPool(capacity int) *GPool

NewGPool 创建一个新的 GPool 实例,参数 capacity 指定了协程池的容量

func (*GPool) Acquire

func (p *GPool) Acquire() bool

Acquire 获取一个可用的协程,如果获取成功返回 true,否则返回 false

func (*GPool) AddJob

func (p *GPool) AddJob(job func(ctx context.Context) error)

AddJob 将一个新的任务加入到待执行队列中

func (*GPool) ErrChan

func (p *GPool) ErrChan() <-chan error

ErrChan 获取错误通道,以便获取协程执行过程中出现的错误

func (*GPool) Go

func (p *GPool) Go(job func(ctx context.Context) error)

Go 提交一个新的任务到协程池中执行,如果当前没有可用的协程,则任务会被加入到待执行队列中

func (*GPool) Release

func (p *GPool) Release()

Release 释放一个协程,供其他任务使用

func (*GPool) Shutdown

func (p *GPool) Shutdown()

Shutdown 关闭协程池,等待所有协程执行完毕,并关闭错误通道

func (*GPool) Wait

func (p *GPool) Wait(timeout time.Duration) bool

Wait 等待所有协程执行完毕,可以设置超时时间

Jump to

Keyboard shortcuts

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