base

package
v0.0.0-...-1a2806f Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// CallObejctType call object type
	CallObejctType      = iota
	CallObejctNormal    = 1 //普通模式
	CallObejctNotify    = 2 //通知模式,无响应
	CallObejctTransport = 3 //透传模式,handler可以收到callobject
)
View Source
const (
	// ErrorCodeID id define
	ErrorCodeID = iota
	//nethopper 1000-2000
	//ErrCodeModule
	ErrCodeModule = 1000
	//ErrCodeWorker
	ErrCodeWorker = 1001
	//ErrCodeProcessor
	ErrCodeProcessor = 1002
	//ErrCodeRouter
	ErrCodeRouter = 1003
	//ErrCodeLogic
	ErrCodeLogic = 1004
)

Variables

View Source
var ErrCallTimeout = errors.New("Timeout on call")
View Source
var ErrQueueEmpty = errors.New("Queue is empty")
View Source
var ErrQueueFull = errors.New("Queue is full")
View Source
var ErrQueueIsClosed = errors.New("Queue is Closed")

ErrQueueIsClosed queue is closed

View Source
var ErrQueueTimeout = errors.New("Timeout on queue")

ErrQueueTimeout queue push or pop timeout

View Source
var ErrReadChanTimeout = errors.New("read channel timeout")
View Source
var ErrWriteChanTimeout = errors.New("write channel timeout")
View Source
var GCallObjectPool = sync.Pool{
	New: func() interface{} {
		return &CallObject{
			Timer: time.NewTimer(TimeoutChanTime),
		}
	},
}
View Source
var TimeoutChanTime = 8 * time.Second

Functions

func CallFunction

func CallFunction(f interface{}, v ...interface{}) []reflect.Value

CallFunction simply to dynamically call a function or a method on an object Calls the callback given by the first parameter and passes the remaining parameters as arguments. Zero or more parameters to be passed to the callback. Returns the return value of the callback.

func CallMethod

func CallMethod(instance interface{}, method string, v ...interface{}) []reflect.Value

CallMethod simply to dynamically call a method on an object Calls the instance given by the first parameter and method name as the second parameter and passes the remaining parameters as arguments. Zero or more parameters to be passed to the method. Returns the return value of the method.

func Future

func Future(f func() (interface{}, error)) func() (interface{}, error)

Future async call function

func GO

func GO(v ...interface{})

GO wapper exec goruntine and ref count

func GOFunction

func GOFunction(ref IRef, v ...interface{})

GOFunction wapper exec goruntine and ref count

func GOFunctionWithWG

func GOFunctionWithWG(wg *sync.WaitGroup, ref IRef, v ...interface{})

GOFunctionWithWG wapper exec goruntine,waitgroup and ref count

func GOMethod

func GOMethod(ref IRef, instance interface{}, method string, v ...interface{})

GOMethod wapper exec class method goruntine and ref count

func GOMethodWithWG

func GOMethodWithWG(wg *sync.WaitGroup, ref IRef, instance interface{}, method string, v ...interface{})

GOMethodWithWG wapper exec goruntine,waitgroup and ref count

func GetClassMethodName

func GetClassMethodName(s IClass) string

GetClassMethodName 获取正在运行的class函数名

func GetFunctionName

func GetFunctionName() string

GetMethodName 获取正在运行的函数名

Types

type AppContext

type AppContext struct {
	WG  *sync.WaitGroup
	Ref IRef
}

func NewAppContext

func NewAppContext() *AppContext

type CallObject

type CallObject struct {
	Caller  ICaller
	CmdID   int32
	Option  int32
	Type    int8
	Args    []interface{}
	Trace   []uint8
	ChanRet chan *Ret
	Timer   *time.Timer
}

CallObject call struct

func NewCallObject

func NewCallObject(caller ICaller, cmdID int32, opt int32, args ...interface{}) *CallObject

NewCallObject create call object

func NewNotifyObject

func NewNotifyObject(caller ICaller, cmdID int32, opt int32, args ...interface{}) *CallObject

NewNotifyObject create notify object

func NewTransportObject

func NewTransportObject(caller ICaller, cmdID int32, opt int32, args ...interface{}) *CallObject

NewTransportObject create transport object

func (*CallObject) Init

func (c *CallObject) Init(t int8, caller ICaller, cmdID int32, opt int32, args ...interface{}) *CallObject

func (*CallObject) Reset

func (c *CallObject) Reset() *CallObject

func (*CallObject) SetRet

func (c *CallObject) SetRet(ret *Ret) bool

func (*CallObject) SetTrace

func (c *CallObject) SetTrace(mid ...uint8)

type Callback

type Callback func(ret *Ret)

type ICaller

type ICaller interface {
	Execute(obj *CallObject) *Ret
}

type IClass

type IClass interface {
	Name() string
}

type IRef

type IRef interface {
	AddRef() int32
	DecRef() int32
	Count() int32
}

func NewRef

func NewRef() IRef

NewRef create Ref instance

type Ref

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

func (*Ref) AddRef

func (r *Ref) AddRef() int32

func (*Ref) Count

func (r *Ref) Count() int32

func (*Ref) DecRef

func (r *Ref) DecRef() int32

type Ret

type Ret struct {
	Data  interface{}
	Code  int32
	Err   error
	Trace []uint8
}

Ret call return object

func NewRet

func NewRet(code int32, err error, data interface{}) *Ret

NewRet create ret object

func (*Ret) Init

func (c *Ret) Init(code int32, err error, data interface{}) *Ret

func (*Ret) Reset

func (c *Ret) Reset() *Ret

func (*Ret) SetTrace

func (c *Ret) SetTrace(mid ...uint8)

Directories

Path Synopsis
Package sync provides synchronization primitive implementations for spinlocks and semaphore.
Package sync provides synchronization primitive implementations for spinlocks and semaphore.

Jump to

Keyboard shortcuts

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