dgpool

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: Apache-2.0 Imports: 6 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 FILOAnywayGo

func FILOAnywayGo(fn func())

FILOAnywayGo 强制执行方法

func FILOGo(fn func()) bool

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

func FILOMustGo

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

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

func FILOTryGo

func FILOTryGo(fn func())

FILOTryGo 尝试执行方法

func SetFILOPool

func SetFILOPool(maxGoroutinesAmount int, maxGoroutineIdleDuration time.Duration)

Types

type FILOPool

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

func NewFILOPool

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

NewFILOPool 创建协程栈池

func (*FILOPool) Go

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

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

func (*FILOPool) MaxGoroutineIdle

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

func (*FILOPool) MaxGoroutinesAmount

func (that *FILOPool) MaxGoroutinesAmount() int

func (*FILOPool) MustGo

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

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

func (*FILOPool) Stop

func (that *FILOPool) Stop()

func (*FILOPool) TryGo

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

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

Jump to

Keyboard shortcuts

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