dgpool

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMaxGoroutinesAmount 默认的协程最大数量
	DefaultMaxGoroutinesAmount = 256 * 1024
	// DefaultMaxGoroutineIdleDuration 默认协程最大空闲时间
	DefaultMaxGoroutineIdleDuration = 10 * time.Second
)

Variables

View Source
var ErrLack = errors.New("lack of goroutines, because exceeded maxGoroutinesAmount limit")

Functions

func Add

func Add(f func()) error

Add 往默认协程池中添加jobs

func AddWithRecover

func AddWithRecover(userFunc func(), recoverFunc ...func(err error)) error

AddWithRecover 在默认协程池中执行方法,并且执行完成后,如果出错,则调用recover方法

func AddWithSyncFunc

func AddWithSyncFunc(useFunc func(), syncFunc func(bool)) error

AddWithSyncFunc 在默认协程池中执行方法,执行完成后回调

func FILOAnywayGo added in v0.1.2

func FILOAnywayGo(fn func())

FILOAnywayGo 强制执行方法

func FILOGo(fn func()) bool

FILOGo 使用栈的形式组织协程执行方法,

func FILOMustGo added in v0.1.2

func FILOMustGo(fn func(), ctx ...context.Context) error

FILOMustGo 强制执行方法,并且传入上下文

func FILOTryGo added in v0.1.2

func FILOTryGo(fn func())

FILOTryGo 尝试执行方法

func Go

func Go(fn func()) bool

Go 执行协程

func Jobs

func Jobs() int

Jobs 默认协程池当前中有多少个任务需要执行

func SetFILOPool added in v0.1.2

func SetFILOPool(maxGoroutinesAmount int, maxGoroutineIdleDuration time.Duration)

func Size

func Size() int

Size 默认协程池的大小

Types

type FILOPool added in v0.1.2

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

func NewFILOPool added in v0.1.2

func NewFILOPool(maxGoroutinesAmount int, maxGoroutineIdleDuration time.Duration) *FILOPool

NewFILOPool 创建协程栈池

func (*FILOPool) Go added in v0.1.2

func (that *FILOPool) Go(fn func()) error

Go 通过 goroutine 执行方法,如果返回值不为nil,则表示超过了最大执行个数

func (*FILOPool) MaxGoroutineIdle added in v0.1.2

func (that *FILOPool) MaxGoroutineIdle() time.Duration

func (*FILOPool) MaxGoroutinesAmount added in v0.1.2

func (that *FILOPool) MaxGoroutinesAmount() int

func (*FILOPool) MustGo added in v0.1.2

func (that *FILOPool) MustGo(fn func(), ctx ...context.Context) error

MustGo 强制执行方法,直到执行完毕,或者上下文取消

func (*FILOPool) Stop added in v0.1.2

func (that *FILOPool) Stop()

func (*FILOPool) TryGo added in v0.1.2

func (that *FILOPool) TryGo(fn func())

TryGo 尝试通过goroutine执行方法,如果不成功,则同步执行

type Pool

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

Pool Goroutine Pool

func New

func New(limit ...int) *Pool

New 创建协程池,limit限制最多能同时运行多少个工作协程

func (*Pool) Add

func (that *Pool) Add(f func()) error

Add 添加待执行的方法到协程池

func (*Pool) AddWithRecover

func (that *Pool) AddWithRecover(useFunc func(), recoverFunc ...func(err error)) error

AddWithRecover 添加任务,并在任务执行出错的情况下,回调recoverFunc

func (*Pool) AddWithSyncFunc

func (that *Pool) AddWithSyncFunc(useFunc func(), syncFunc func(bool)) error

AddWithSyncFunc 执行成功后回调方法

func (*Pool) Cap

func (that *Pool) Cap() int

Cap 协程池最大能够启动多少个协程

func (*Pool) Close

func (that *Pool) Close()

Close 关闭协程池

func (*Pool) IsClosed

func (that *Pool) IsClosed() bool

IsClosed 判断协程池是否关闭

func (*Pool) Jobs

func (that *Pool) Jobs() int

Jobs 协程池中的待执行任务数量

func (*Pool) Size

func (that *Pool) Size() int

Size 协程池中的协程数量

Jump to

Keyboard shortcuts

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