handle

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pcall

func Pcall(method *reflect.Method, args []reflect.Value) (rets []any, err error)

Pcall 带兜底的反射调用

@param method
@param args
@return rets
@return err

Types

type Handler

type Handler struct {
	Type       reflect.Type // low-level type of method
	Method     *reflect.Method
	MethodType MethodType
}

Handler represents a message.Message's handler's meta information.

type HandlerPool

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

func NewHandlerPool

func NewHandlerPool() *HandlerPool

func (*HandlerPool) GetHandle added in v1.0.2

func (h *HandlerPool) GetHandle(targetName string, methodName string) *Handler

func (*HandlerPool) ProcessHandler added in v1.0.2

func (h *HandlerPool) ProcessHandler(handler *Handler, receiver reflect.Value, args ...any) (methodType MethodType, rets []any, err error)

ProcessHandler handle方法反射调用

@receiver h
@param handler
@param receiver receiver的 reflect.Value
@param args
@return methodType 方法类型
@return rets
@return err

func (*HandlerPool) ProcessHandlerMessage

func (h *HandlerPool) ProcessHandlerMessage(receiverName string, receiver reflect.Value, methodName string, args ...any) (methodType MethodType, rets []any, err error)

ProcessHandlerMessage handle方法反射调用

@receiver h
@param receiverName 缓存中注册的名字
@param receiverInstance receiver的实例
@param methodName 方法名
@param args 入参
@return methodType 方法类型
@return rets
@return error

func (*HandlerPool) Register

func (h *HandlerPool) Register(name string, target any) (err error)

Register 注册代理类的反射信息

@receiver h
@param name
@param target 插桩:该实例仅用于反射获取方法元数据,实际调用时并不会用该实例作为方法的receiver

type MethodType added in v1.0.2

type MethodType int

MethodType 支持的方法签名类型

const (
	MtNone                   MethodType = iota // 无
	MtFullStyle                                // 完全形态签名:(receiver) func(eventType bcore.EventType, delta time.Duration) bcore.Result
	MtSimpleAction                             // 简单任务签名:(receiver) func()
	MtSimpleActionWithErr                      // 简单任务带错误返回的签名:(receiver) func() error
	MtSimpleActionWithResult                   // 简单任务带 bcore.Result 返回的签名:(receiver) func() bcore.Result
)

type Option

type Option func(options *options)

Option used to customize handler

func WithName

func WithName(name string) Option

WithName used to rename component name

func WithNameFunc

func WithNameFunc(fn func(string) string) Option

WithNameFunc override handler name by specific function such as: strings.ToUpper/strings.ToLower

func WithTaskGoProvider

func WithTaskGoProvider(taskGoProvider func(task func())) Option

WithTaskGoProvider 注册延迟动态绑定的异步任务派发线程

@param taskGoProvider
@return Option

Jump to

Keyboard shortcuts

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