exec

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const StatusDone = 1
View Source
const StatusOvertime = 2
View Source
const StatusWait = 0

Variables

This section is empty.

Functions

func CallFunc

func CallFunc(body CallBody) (result []interface{}, err error)

CallFunc 利用反射动态执行函数

func Worker

func Worker(ctx context.Context, jobs <-chan CallBody, result chan<- CallBody)

Worker 工作线程

Types

type CallBody

type CallBody struct {
	Status   int           // 执行状态
	Index    int           // 传入时的顺序
	FuncName interface{}   // 要执行的函数本体
	Params   []interface{} // 要传的函数参数, 需要类型和数量都保持一致
	Result   []interface{} // 函数返回的所有结果(对应多参数返回)
	Err      error         // 函数在 callBack 里调用时的错误
}

CallBody 单个函数的请求体

func FuncWithTimeout added in v0.1.5

func FuncWithTimeout(maxTime time.Duration, funcName interface{}, args ...interface{}) *CallBody

FuncWithTimeout 带超时时间的函数

func (*CallBody) GetResult

func (cb *CallBody) GetResult(returnItems ...interface{}) error

GetResult 将返回结果以反射的方式赋值给传入参数

type CallTask

type CallTask struct {
	MaxTime  time.Duration // 最大执行时间
	TaskList []CallBody    // 执行的任务列表
	Ctx      context.Context
	WorkNum  int
}

CallTask 发起并发执行任务

func (*CallTask) AddTask

func (task *CallTask) AddTask(job CallBody) *CallTask

AddTask 添加工作任务

func (*CallTask) BatchExec

func (task *CallTask) BatchExec() error

Jump to

Keyboard shortcuts

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