routine

package
v1.5.5 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NoEnableRoutinePool = errors.New("not enable routine pool, please add enableRtePool field to settings")
	EmptyTaskFunc       = errors.New("task func is nil")
)

Functions

func AddTask

func AddTask(taskFunc TaskFunc) error

AddTask 添加任务.

func CloseDefaultTask added in v1.2.2

func CloseDefaultTask() error

func CountInfo

func CountInfo() (map[string]int, error)

CountInfo 获取协程池个数信息.

func SetUpDefaultTask

func SetUpDefaultTask(conf Routine) func() error

SetUpDefaultTask 初始化后台任务.

Types

type LogHandlerFunc added in v1.3.2

type LogHandlerFunc func(string, ...interface{})

func (LogHandlerFunc) Printf added in v1.3.2

func (d LogHandlerFunc) Printf(format string, args ...interface{})

type Routine added in v1.3.2

type Routine struct {
	// MaxWorkerCount 最大worker数量, 默认是10
	MaxWorkerCount int `json:"maxWorkerCount" yaml:"maxWorkerCount"`
	// FreeMaxLifetime 协程最大闲置时间, 默认是20分钟, 单位: 秒
	FreeMaxLifetime int `json:"freeMaxLifetime" yaml:"freeMaxLifetime"`
	// PanicHandler panic处理器
	PanicHandler func(interface{})
	// Logger 日志处理器
	Logger LogHandlerFunc
	// UseRawWhenBusy worker用尽, 使用原生协程执行
	UseRawWhenBusy bool `json:"useRawGoroutine" yaml:"useRawGoroutine"`
}

Routine 协程池配置.

type Task

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

func SetUp

func SetUp(conf Routine) (*Task, error)

SetUp 初始化协程池.

func (*Task) AsyncDO

func (task *Task) AsyncDO(taskFunc TaskFunc) error

AsyncDO 添加任务, 如果有设置.

func (*Task) Close

func (task *Task) Close()

Close 关闭协程池.

func (Task) CountInfo

func (task Task) CountInfo() map[string]int

CountInfo 获取协程池个数信息.

func (*Task) RawGoroutineCount added in v1.2.9

func (task *Task) RawGoroutineCount() int64

RawGoroutineCount 获取当前执行任务的原生协程数.

func (*Task) Reboot

func (task *Task) Reboot()

Reboot 重启关闭的协程池.

type TaskFunc

type TaskFunc func()

Jump to

Keyboard shortcuts

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