evn

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const C_TASK_EXIT_TIME_OUT = 2 * time.Second // task  退出超时

Variables

This section is empty.

Functions

func Install

func Install(conf *Config) ctl.IControler

安装控制器

func Listen

func Listen(event IEvent, handle TEventHandler)

Listen 动态监听事件(一般情况下使用Register)

func Post

func Post(event IEvent, orderly ...bool)

投递事件(orderly:此事件是否需要被有序处理)

func PostDo

func PostDo(event IEventDo, orderly ...bool)

投递事件并自动监听(orderly:此事件是否需要被有序处理)

func Register

func Register(id TEventID, handle TEventHandler)

Register 预注册监听事件

Types

type Config

type Config struct {
	Size int // 处理事件的任务数量
	Capy int // 每个任务的通道能力

} //

type Event

type Event struct {
	Id TEventID

} //

事件基本结构(供业务简单使用)

func (*Event) EventId

func (e *Event) EventId() TEventID

type EventDo

type EventDo struct {
	Id  TEventID
	Fun func()

} //

func EventDoFun

func EventDoFun(do func()) EventDo

事件(闭包)结构(供业务继承)

func (*EventDo) Do

func (e *EventDo) Do()

func (*EventDo) EventId

func (e *EventDo) EventId() TEventID

type IContrler

type IContrler interface {
	ctl.IControler

	// 监听事件(eventId重复则进行覆盖)
	Listen(event IEvent, handle TEventHandler)

	// 投递事件(sync:此时间是否需要被同步有序处理)
	Post(event IEvent, sync ...bool)

	// 投递事件并自动监听(sync:此时间是否需要被同步有序处理)
	PostDo(event IEventDo, sync ...bool)
}

> 控制器接口

var (
	Ctl IContrler // 默认事件系统控制器

)

func Controller

func Controller(conf *Config) IContrler

type IEvent

type IEvent interface {
	EventId() TEventID
}

> 事件对象接口

type IEventDo

type IEventDo interface {
	IEvent
	Do()
}

> 事件(闭包)接口

type TEventHandler

type TEventHandler func(IEvent)

事件处理器原型

type TEventID

type TEventID = string

事件Id类型

type Task

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

Task

func (*Task) Exit

func (this *Task) Exit()

func (*Task) HandleFunc

func (this *Task) HandleFunc(handFun TaskHandFunc)

func (*Task) Handler

func (this *Task) Handler(handler TaskHandler)

func (*Task) Init

func (this *Task) Init(name string, capy int) *Task

func (*Task) Post

func (this *Task) Post(param interface{}, donefun_ ...func(result interface{}, err error))

type TaskHandFunc

type TaskHandFunc func(param interface{}) (ret interface{}, err error)

func (TaskHandFunc) OnHandleTask

func (f TaskHandFunc) OnHandleTask(param interface{}) (ret interface{}, err error)

type TaskHandler

type TaskHandler interface {
	OnHandleTask(param interface{}) (ret interface{}, err error)
}

==================== Task

Jump to

Keyboard shortcuts

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