core

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

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

Pool 协程池

func NewPool

func NewPool(ctx context.Context, cfg config.PoolConfig, handler RejectedHandler,
	workerHook []WorkerStatusChangeHook, poolHook []PoolStatusChangeHook) (*Pool, error)

func (*Pool) Go

func (p *Pool) Go(f func())

Go 增加任务

func (*Pool) GoWithTimeout

func (p *Pool) GoWithTimeout(f func(), timeout time.Duration)

func (*Pool) Shutdown

func (p *Pool) Shutdown()

Shutdown 关闭

func (*Pool) Stop

func (p *Pool) Stop()

type PoolStatus

type PoolStatus int64
const (
	PoolStatusInit       PoolStatus = iota + 1 // 初始化中
	PoolStatusWorking                          // 运行中
	PoolStatusShutdown                         // 关闭状态,不接受新的任务,执行完已有任务后终止
	PoolStatusStop                             // 中断状态
	PoolStatusTerminated                       // 终止状态
)

func (PoolStatus) String

func (p PoolStatus) String() string

type PoolStatusChangeHook

type PoolStatusChangeHook interface {
	OnChange(status PoolStatus)
}

type RejectedHandler

type RejectedHandler interface {
	RejectedExecution(task func())
}

RejectedHandler rejected handler

type Worker

type Worker struct {
	Id int64 // 唯一 id

	FreeBeginTime time.Time // 空闲开始时间
	// contains filtered or unexported fields
}

Worker 执行者

func (*Worker) ResetFreeTime

func (p *Worker) ResetFreeTime()

func (*Worker) ShouldTerminal

func (p *Worker) ShouldTerminal() bool

ShouldTerminal check over core size

type WorkerStatus

type WorkerStatus int64
const (
	WorkerStatusReady      WorkerStatus = iota + 1 // 就绪
	WorkerStatusRunning                            // 运行中
	WorkerStatusShutdown                           // 关闭状态,不拉取新的任务,执行完任务后终止
	WorkerStatusStop                               // 中断状态,直接终止
	WorkerStatusTidying                            // 空闲状态
	WorkerStatusTerminated                         // 已经终止

	WorkerStatusCreate
)

func (WorkerStatus) String

func (w WorkerStatus) String() string

type WorkerStatusChangeHook

type WorkerStatusChangeHook interface {
	OnChange(workerId int64, lastStatus WorkerStatus, nextStatus WorkerStatus)
}

Jump to

Keyboard shortcuts

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